Example usage for com.badlogic.gdx.graphics.g2d TextureAtlas findRegions

List of usage examples for com.badlogic.gdx.graphics.g2d TextureAtlas findRegions

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d TextureAtlas findRegions.

Prototype

public Array<AtlasRegion> findRegions(String name) 

Source Link

Document

Returns all regions with the specified name, ordered by smallest to largest AtlasRegion#index index .

Usage

From source file:ca.hiphiparray.amazingmaze.Assets.java

License:Open Source License

/** Helper method to setup the mouse animation. */
private void setupMouseAnimation() {
    TextureAtlas atlas = manager.get(Assets.GAME_ATLAS_LOCATION, TextureAtlas.class); // Reference used for readability.
    mouseUp = new Animation<TextureRegion>(MOUSE_FRAME_DURATION,
            atlas.findRegions(Assets.MOUSE + Assets.UP_MODIFIER), PlayMode.LOOP_PINGPONG);
    mouseDown = new Animation<TextureRegion>(MOUSE_FRAME_DURATION,
            atlas.findRegions(Assets.MOUSE + Assets.DOWN_MODIFIER), PlayMode.LOOP_PINGPONG);
    mouseLeft = new Animation<TextureRegion>(MOUSE_FRAME_DURATION,
            atlas.findRegions(Assets.MOUSE + Assets.LEFT_MODIFIER), PlayMode.LOOP_PINGPONG);
    mouseRight = new Animation<TextureRegion>(MOUSE_FRAME_DURATION,
            atlas.findRegions(Assets.MOUSE + Assets.RIGHT_MODIFIER), PlayMode.LOOP_PINGPONG);

    assert mouseUp
            .getKeyFrames().length == MOUSE_FRAME_COUNT : "mouseUp frame count does not match MOUSE_FRAME_COUNT.";
    assert mouseDown
            .getKeyFrames().length == MOUSE_FRAME_COUNT : "mouseDown frame count does not match MOUSE_FRAME_COUNT.";
    assert mouseLeft
            .getKeyFrames().length == MOUSE_FRAME_COUNT : "mouseLeft frame count does not match MOUSE_FRAME_COUNT.";
    assert mouseRight
            .getKeyFrames().length == MOUSE_FRAME_COUNT : "mouseRight frame count does not match MOUSE_FRAME_COUNT.";
}

From source file:com.arkanoid.Actors.ActorFactory.java

License:Open Source License

/**
 * Create a player using the default texture.
 * @param world     world where the player will have to live in.
 * @param position  initial position ofr the player in the world (meters,meters).
 * @return          a player./*from   w w w.j a va 2s .  c om*/
 */
public PlayerActor createPlayer(World world, Vector2 position) {
    //Texture playerTexture = manager.get("player.png");
    TextureAtlas atlas = manager.get("sprites_player.txt", TextureAtlas.class);
    HashMap<PlayerActor.PlayerAnimations, Animation> animations = new HashMap<PlayerActor.PlayerAnimations, Animation>();

    Array<TextureAtlas.AtlasRegion> playerRegions = atlas.findRegions("red_medium");
    Array<TextureAtlas.AtlasRegion> playerRegionsReverse = atlas.findRegions("red_medium");
    playerRegionsReverse.reverse();
    playerRegions.addAll(playerRegionsReverse);
    animations.put(PlayerActor.PlayerAnimations.RED_MEDIUM,
            new Animation(1f / (float) playerRegions.size, playerRegions));

    playerRegions = atlas.findRegions("red_large");
    playerRegionsReverse = atlas.findRegions("red_large");
    playerRegionsReverse.reverse();
    playerRegions.addAll(playerRegionsReverse);
    animations.put(PlayerActor.PlayerAnimations.RED_LARGE,
            new Animation(1f / (float) playerRegions.size, playerRegions));

    playerRegions = atlas.findRegions("red_medium_create");
    animations.put(PlayerActor.PlayerAnimations.RED_MEDIUM_CREATE,
            new Animation(1f / (float) playerRegions.size, playerRegions));

    playerRegions = atlas.findRegions("red_medium_destoy");
    animations.put(PlayerActor.PlayerAnimations.RED_MEDIUM_DESTROY,
            new Animation(1f / (float) playerRegions.size, playerRegions));

    playerRegions = atlas.findRegions("blue_medium");
    playerRegionsReverse = atlas.findRegions("blue_medium");
    playerRegionsReverse.reverse();
    playerRegions.addAll(playerRegionsReverse);
    animations.put(PlayerActor.PlayerAnimations.BLUE_MEDIUM,
            new Animation(1f / (float) playerRegions.size, playerRegions));

    playerRegions = atlas.findRegions("blue_large");
    playerRegionsReverse = atlas.findRegions("blue_large");
    playerRegionsReverse.reverse();
    playerRegions.addAll(playerRegionsReverse);
    animations.put(PlayerActor.PlayerAnimations.BLUE_LARGE,
            new Animation(1f / (float) playerRegions.size, playerRegions));

    playerRegions = atlas.findRegions("blue_medium_create");
    animations.put(PlayerActor.PlayerAnimations.BLUE_MEDIUM_CREATE,
            new Animation(1f / (float) playerRegions.size, playerRegions));

    playerRegions = atlas.findRegions("blue_medium_destoy");
    animations.put(PlayerActor.PlayerAnimations.BLUE_MEDIUM_DESTROY,
            new Animation(1f / (float) playerRegions.size, playerRegions));

    return new PlayerActor(world, animations, position);
}

From source file:com.arkanoid.Actors.ActorFactory.java

License:Open Source License

public BlockActor createBlock(World world, Vector2 position, String color) {

    TextureAtlas atlas = manager.get("sprites_board.txt", TextureAtlas.class);
    TextureRegion texture = atlas.findRegion("block_" + color);
    Animation animation = null;/*from www.ja va2  s .  co m*/

    int hardness = 1;
    if (color.equals("plate") || color.equals("golden")) {
        hardness = color.equals("golden") ? 99 : 2;
        Array<TextureAtlas.AtlasRegion> blockRegions = atlas.findRegions("block_" + color);
        animation = new Animation(0.5f / (float) blockRegions.size, blockRegions);
    }

    BlockActor block = new BlockActor(world, position, texture, animation, hardness);
    if (color.equals("plate") || color.equals("golden")) {
        block.StartAnimation();
    }
    return block;
}

From source file:com.bagon.matchteam.mtx.animation.AnimationCreator.java

License:Apache License

/**
 * Get animation from texture atlas (Based on TexturePacker). Each frames'
 * base name should be same. This is for multi textures, (Each frame stored
 * individually in texture atlas)/*from   www.  j  a  va  2  s. co  m*/
 * <p>
 * EXAMPLE: <br>
 * baseName = "walk"<br>
 * frame1 = "walk00" (Actual name in texture atlas)<br>
 * frame2 = "walk01" (Actual name in texture atlas)<br>
 * frame3 = "walk02" (Actual name in texture atlas)<br>
 * ...
 * 
 * @param textureAtlas
 *            atlas which contains texture frames
 * @param animationBaseName
 *            base name of the frames in atlas
 * @param numberOfFrames
 *            number of frames of the animation
 * @param frameDuration
 *            each frame duration on play
 * @return animation created
 * 
 * */
public static Animation getAnimationFromMultiTextures(TextureAtlas textureAtlas, String animationBaseName,
        int numberOfFrames, float frameDuration, boolean flipX, boolean flipY) {
    // Key frames list
    TextureRegion[] keyFrames = new TextureRegion[numberOfFrames];

    // Set key frames (each textures region from atlas)
    for (int i = 0; i < numberOfFrames; i++) {
        TextureRegion frame = textureAtlas.findRegions(animationBaseName).get(i);
        frame.flip(flipX, flipY);
        keyFrames[i] = frame;
    }

    //
    Animation animation = new Animation(frameDuration, keyFrames);
    return animation;
}

From source file:com.bladecoder.engine.assets.EngineAssetManager.java

License:Apache License

public Array<AtlasRegion> getRegions(String atlas, String name) {
    TextureAtlas a = get(ATLASES_DIR + atlas + ATLAS_EXT, TextureAtlas.class);

    Array<AtlasRegion> region = a.findRegions(name);

    if (region == null) {
        EngineLogger.error("Regions for " + name + " not found in atlas " + atlas);
    }/* w  ww  . j  a  v  a2 s.  c  o  m*/

    return region;
}

From source file:com.dongbat.invasion.screen.LoadingScreen.java

@Override
public void show() {
    // Tell the manager to load assets for the loading screen
    manager.load("data/loading.pack", TextureAtlas.class);
    // Wait until they are finished loading
    manager.finishLoading();//from ww  w .j  av a 2  s  .co m
    // Initialize the stage where we will place everything
    stage = new Stage();
    // Get our textureatlas from the manager
    TextureAtlas atlas = manager.get("data/loading.pack", TextureAtlas.class);
    // Grab the regions from the atlas and create some images
    logo = new Image(atlas.findRegion("libgdx-logo"));
    loadingFrame = new Image(atlas.findRegion("loading-frame"));
    loadingBarHidden = new Image(atlas.findRegion("loading-bar-hidden"));
    screenBg = new Image(atlas.findRegion("screen-bg"));
    loadingBg = new Image(atlas.findRegion("loading-frame-bg"));
    // Add the loading bar animation
    Animation anim = new Animation(0.05f, atlas.findRegions("loading-bar-anim"));
    anim.setPlayMode(Animation.PlayMode.LOOP_REVERSED);
    loadingBar = new LoadingBar(anim);
    // Add all the actors to the stage
    stage.addActor(screenBg);
    stage.addActor(loadingBar);
    stage.addActor(loadingBg);
    stage.addActor(loadingBarHidden);
    stage.addActor(loadingFrame);
    stage.addActor(logo);
    // Add everything to be loaded, for instance:
    UpgradeUtil.load();
    AtlasRegistry.load();
    AssetUtil.load();

    AbilityRegistry.load();
    BuffRegistry.load();
    PlayerInputUtil.init();
    BulletRegistry.load();
    EnemyRegistry.load();
}

From source file:com.dongbat.invasion.util.AnimationUtil.java

public static Animation get(String name, float frameDuration) {
    if (cache.containsKey(name)) {
        return cache.get(name);
    }/*w ww . java  2 s.  c o  m*/
    String[] parts = name.split("/");
    TextureAtlas atlas = AtlasRegistry.getAtlas(parts[0]);
    Array<TextureAtlas.AtlasRegion> regions = atlas.findRegions(parts[1]);

    Animation animation = new Animation(frameDuration, regions);
    cache.put(name, animation);
    return animation;
}

From source file:com.kasetagen.game.bubblerunner.screen.BubbleRunnerMenu.java

License:Creative Commons License

private void assembleMenuGroup(TextureAtlas atlas) {

    infiniteLeftDecorator = new ActorDecorator() {
        @Override//from   w w  w  . java  2 s.c  o  m
        public void applyAdjustment(Actor actor, float v) {
            if (actor.getRight() <= 0f) {
                actor.setPosition(actor.getX() + (actor.getWidth() * 2f), 0f);
            }
        }
    };

    checkedMenuOptionDecorator = new PulsingScaleDecorator(0.025f, 1f);

    float w = stage.getWidth();
    float h = stage.getHeight();
    //Add BG
    bgGroup.addActor(new GenericActor(0f, 0f, w, h, atlas.findRegion(AtlasUtil.ANI_TITLE_BG), Color.BLACK));

    GenericActor moon = new GenericActor(600f, 500f, MOON_WIDTH, MOON_HEIGHT,
            atlas.findRegion(AtlasUtil.ANI_TITLE_MOON), Color.YELLOW);
    moon.addDecorator(new ShakeDecorator(5f, 5f, 4f));
    moon.addDecorator(new OscillatingDecorator(5f, 10f, 2.5f));
    bgGroup.addActor(moon);
    //add Clouds5 setup
    addClouds(atlas.findRegion(AtlasUtil.ANI_TITLE_C5), -25f);

    //Add Skyline2
    bgGroup.addActor(
            new GenericActor(0f, 0f, w, h, atlas.findRegion(AtlasUtil.ANI_TITLE_SKYLINE2), Color.BLACK));

    //Add Cloud 4
    addClouds(atlas.findRegion(AtlasUtil.ANI_TITLE_C4), -25f);

    //Add Cloud 3
    addClouds(atlas.findRegion(AtlasUtil.ANI_TITLE_C3), -75f);

    //Add Skyline1
    bgGroup.addActor(
            new GenericActor(0f, 0f, w, h, atlas.findRegion(AtlasUtil.ANI_TITLE_SKYLINE1), Color.BLACK));

    //Add Title
    bgGroup.addActor(new GenericActor(150f, 25f, TITLE_WIDTH, TITLE_HEIGHT,
            atlas.findRegion(AtlasUtil.ANI_TITLE_TITLE), Color.WHITE));

    //Add Cloud 2
    addClouds(atlas.findRegion(AtlasUtil.ANI_TITLE_C2), -100);

    //Add Cloud 1
    addClouds(atlas.findRegion(AtlasUtil.ANI_TITLE_C1), -125f);

    //Add Platform
    menuGroup.addActor(
            new GenericActor(0f, 0f, w, h, atlas.findRegion(AtlasUtil.ANI_TITLE_PLATFORM), Color.BLACK));

    //Add Edison
    Animation eddyAni = new Animation(EDISON_CYCLE_RATE, atlas.findRegions(AtlasUtil.ANI_TITLE_EDISON));
    menuGroup.addActor(new AnimatedActor(0f, 0f, EDISON_WIDTH, EDISON_HEIGHT, eddyAni, 0f));
    //Add Edyn
    Animation edynAni = new Animation(EDYN_CYCLE_RATE, atlas.findRegions(AtlasUtil.ANI_TITLE_EDYN));
    menuGroup.addActor(new AnimatedActor(w - EDYN_WIDTH, 0f, EDYN_WIDTH, EDYN_HEIGHT, edynAni, 0f));

    Animation edynEyes = new Animation(EYE_CYCLE_RATE, atlas.findRegions(AtlasUtil.ANI_TITLE_EDYN_EYES));
    AnimatedActor eyes = new AnimatedActor(w - EDYN_WIDTH, 0f, EDYN_WIDTH, EDYN_HEIGHT, edynEyes, 0f);
    eyes.setIsLooping(false);
    eyes.addDecorator(new ActorDecorator() {
        private float secondsBeforeBlink = 0f;
        private float elapsedSeconds = 0f;
        private Random rand = new Random(System.currentTimeMillis());

        @Override
        public void applyAdjustment(Actor actor, float v) {
            AnimatedActor a = ((AnimatedActor) actor);

            if (a.isAnimationComplete()) {
                elapsedSeconds += v;
                if (elapsedSeconds >= secondsBeforeBlink) {
                    a.setState(AnimatedActor.DEFAULT_STATE, true);
                    elapsedSeconds = 0f;
                    secondsBeforeBlink = rand.nextInt(MAX_BLINK_INTERVAL) + MIN_BLINK_INTERVAL;
                }
            }
        }
    });

    menuGroup.addActor(eyes);

    Array<TextureAtlas.AtlasRegion> escapeImgs = atlas.findRegions(AtlasUtil.ANI_TITLE_PLAY_BTN);
    TextureRegionDrawable escapeUp = new TextureRegionDrawable(escapeImgs.get(0));
    TextureRegionDrawable escapeDown = new TextureRegionDrawable(escapeImgs.get(1));

    startGameButton = new ImageButton(escapeUp, escapeDown, escapeDown);
    startGameButton.setSize(PLAY_BTN_WIDTH, PLAY_BTN_HEIGHT);
    startGameButton.addListener(listener);
    //startGameButton.setPosition(buttonX, buttonY);
    startGameButton.setChecked(true);

    startUiContainer = new DecoratedUIContainer(startGameButton);
    startUiContainer.setSize(PLAY_BTN_WIDTH, PLAY_BTN_HEIGHT);
    startUiContainer.setPosition(buttonX, buttonY);
    startUiContainer.addDecorator(checkedMenuOptionDecorator);
    menuGroup.addActor(startUiContainer);

    Array<TextureAtlas.AtlasRegion> optionsImgs = atlas.findRegions(AtlasUtil.ANI_TITLE_OPT_BTN);
    TextureRegionDrawable optionsUp = new TextureRegionDrawable(optionsImgs.get(0));
    TextureRegionDrawable optionsDown = new TextureRegionDrawable(optionsImgs.get(1));
    optionsButton = new ImageButton(optionsUp, optionsDown, optionsDown);
    optionsButton.setSize(OPTS_BTN_WIDTH, OPTS_BTN_HEIGHT);

    //optionsButton.setPosition(buttonX, buttonY - (optionsButton.getHeight()));
    optionsButton.addListener(listener);
    optionsUiContainer = new DecoratedUIContainer(optionsButton);
    optionsUiContainer.setPosition(buttonX, buttonY - (PLAY_BTN_HEIGHT));
    optionsUiContainer.setSize(OPTS_BTN_WIDTH, OPTS_BTN_HEIGHT);
    //optUiContainer.addDecorator(checkedMenuOptionDecorator);
    menuGroup.addActor(optionsUiContainer);

    Array<TextureAtlas.AtlasRegion> hsImgs = atlas.findRegions(AtlasUtil.ANI_TITLE_HIGHSCORE_BTN);
    TextureRegionDrawable hsUp = new TextureRegionDrawable(hsImgs.get(0));
    TextureRegionDrawable hsDown = new TextureRegionDrawable(hsImgs.get(1));

    highScoreButton = new ImageButton(hsUp, hsDown, hsDown);
    highScoreButton.setSize(HS_BTN_WIDTH, HS_BTN_HEIGHT);
    highScoreButton.addListener(listener);

    highScoreUiContainer = new DecoratedUIContainer(highScoreButton);
    highScoreUiContainer.setSize(HS_BTN_WIDTH, HS_BTN_HEIGHT);
    highScoreUiContainer.setPosition(buttonX, optionsUiContainer.getY() - (PLAY_BTN_HEIGHT));
    menuGroup.addActor(highScoreUiContainer);
}

From source file:com.kasetagen.game.bubblerunner.screen.BubbleRunnerMenu.java

License:Creative Commons License

private void assembleOptionsGroup(TextureAtlas atlas) {

    /*/*  ww w .  j a va  2 s . c  om*/
     * Gather values
     */
    float sfxVolValue = gameProcessor.getStoredFloat(GameOptions.SFX_MUSIC_VOLUME_PREF_KEY);
    sfxVolValue = sfxVolValue < 0f ? 0f : sfxVolValue;
    float bgVolValue = gameProcessor.getStoredFloat(GameOptions.BG_MUSIC_VOLUME_PREF_KEY);
    bgVolValue = bgVolValue < 0f ? 0f : bgVolValue;

    charValue = gameProcessor.getStoredString(GameOptions.CHARACTER_SELECT_KEY);
    if (charValue == null || "".equals(charValue.trim())) {
        charValue = AnimationUtil.CHARACTER_2;
    }

    /*
     * Gather Reference Interatctions
     */
    Skin skin = gameProcessor.getAssetManager().get(AssetsUtil.DEFAULT_SKIN, AssetsUtil.SKIN);
    sfx = gameProcessor.getAssetManager().get(AssetsUtil.SND_SHIELD_ON, AssetsUtil.SOUND);

    /*
     * Add Scaffolding
     */
    GenericActor runnerScaffold = new GenericActor(0f, 0f, optionsGroup.getWidth(), optionsGroup.getHeight(),
            atlas.findRegion(AtlasUtil.ANI_OPTIONS_RUNNERSCAFFOLD), Color.WHITE);
    optionsGroup.addActor(runnerScaffold);

    GenericActor volumeScaffold = new GenericActor(0f, 0f, optionsGroup.getWidth(), optionsGroup.getHeight(),
            atlas.findRegion(AtlasUtil.ANI_OPTIONS_VOLUMESCAFFOLD), Color.WHITE);
    optionsGroup.addActor(volumeScaffold);

    Animation techAAni = new Animation(1f / 2f, atlas.findRegions(AtlasUtil.ANI_OPTIONS_TECH_A));
    AnimatedActor techA = new AnimatedActor(TECHA_X, TECHA_Y, TECHA_W, TECHA_H, techAAni, 0f);
    optionsGroup.addActor(techA);
    Animation techBAni = new Animation(1f / 2f, atlas.findRegions(AtlasUtil.ANI_OPTIONS_TECH_B));
    AnimatedActor techB = new AnimatedActor(TECHB_X, TECHB_Y, TECHB_W, TECHB_H, techBAni, 0f);
    optionsGroup.addActor(techB);

    /*
     * Add Player Buttons
     */
    Animation charAni = new Animation(1f, atlas.findRegions(AtlasUtil.ANI_OPTIONS_CHARSELECT));
    charIndicator = new AnimatedActor(CHAR_SEL_X, CHAR_SEL_Y, CHAR_SEL_W, CHAR_SEL_H, charAni, 0f);
    charIndicator.setTargetKeyFrame(1);
    optionsGroup.addActor(charIndicator);

    Animation edynDefCircleAni = new Animation(0.5f / 10f, atlas.findRegions(AtlasUtil.ANI_OPTIONS_EDYN_SELECT),
            Animation.PlayMode.REVERSED);
    Animation edynCircleAni = new Animation(0.5f / 10f, atlas.findRegions(AtlasUtil.ANI_OPTIONS_EDYN_SELECT));
    edynCircle = new AnimatedActor(EDYN_CIRCLE_X, EDYN_CIRCLE_Y, EDYN_CIRCLE_W, EDYN_CIRCLE_H, edynDefCircleAni,
            0f);
    edynCircle.addStateAnimation("SELECTED", edynCircleAni);
    edynCircle.setIsLooping(false);
    optionsGroup.addActor(edynCircle);
    Array<TextureAtlas.AtlasRegion> edynImgs = atlas.findRegions(AtlasUtil.ANI_OPTIONS_EDYN_EYES);
    TextureRegionDrawable edynUp = new TextureRegionDrawable(edynImgs.get(0));
    TextureRegionDrawable edynDown = new TextureRegionDrawable(edynImgs.get(1));
    edynSelect = new ImageButton(edynUp, edynDown, edynDown);

    edynSelect.setSize(CHAR_CIRCLE_SIZE, CHAR_CIRCLE_SIZE);
    edynSelect.setPosition(EDYN_SELECT_X, CHAR_CIRCLE_Y);
    edynSelect.addListener(listener);
    edynSelect.setChecked(AnimationUtil.CHARACTER_2.equals(charValue));
    optionsGroup.addActor(edynSelect);

    Animation eddyDefCircleAni = new Animation(0.5f / 10f,
            atlas.findRegions(AtlasUtil.ANI_OPTIONS_EDISON_SELECT), Animation.PlayMode.REVERSED);
    Animation eddyCircleAni = new Animation(0.5f / 10f, atlas.findRegions(AtlasUtil.ANI_OPTIONS_EDISON_SELECT));
    eddyCircle = new AnimatedActor(EDISON_CIRCLE_X, EDISON_CIRCLE_Y, EDISON_CIRCLE_W, EDISON_CIRCLE_H,
            eddyDefCircleAni, 0f);
    eddyCircle.addStateAnimation("SELECTED", eddyCircleAni);
    eddyCircle.setIsLooping(false);
    optionsGroup.addActor(eddyCircle);

    Array<TextureAtlas.AtlasRegion> edisonImgs = atlas.findRegions(AtlasUtil.ANI_OPTIONS_EDISON_EYES);
    TextureRegionDrawable edisonUp = new TextureRegionDrawable(edisonImgs.get(0));
    TextureRegionDrawable edisonDown = new TextureRegionDrawable(edisonImgs.get(1));
    edisonSelect = new ImageButton(edisonUp, edisonDown, edisonDown);
    edisonSelect.setSize(CHAR_CIRCLE_SIZE, CHAR_CIRCLE_SIZE);
    edisonSelect.setPosition(EDISON_SELECT_X, CHAR_CIRCLE_Y);
    edisonSelect.addListener(listener);
    edisonSelect.setChecked(AnimationUtil.CHARACTER_1.equals(charValue));
    optionsGroup.addActor(edisonSelect);

    charDataSaver = new IDataSaver() {
        @Override
        public void updatePreferences(Preferences prefs) {
            prefs.putString(GameOptions.CHARACTER_SELECT_KEY, charValue);
        }
    };

    /*
     * Add Main Menu Button
     */
    Array<TextureAtlas.AtlasRegion> mmImgs = atlas.findRegions(AtlasUtil.ANI_OPTIONS_MAINMENU);
    TextureRegionDrawable mmDown = new TextureRegionDrawable(mmImgs.get(1));
    mainMenuButton = new ImageButton(new TextureRegionDrawable(mmImgs.get(0)), mmDown, mmDown);
    mainMenuButton.setSize(MM_W, MM_H);
    mainMenuButton.setPosition(MM_X, MM_Y);
    mainMenuButton.addListener(listener);
    optionsGroup.addActor(mainMenuButton);

    /*
     * Add Sliders
     */
    Animation bgAni = new Animation(1f, atlas.findRegions(AtlasUtil.ANI_OPTIONS_MUSIC));
    bgIndicator = new AnimatedActor(MUSIC_X, MUSIC_Y, MUSIC_W, MUSIC_H, bgAni, 0f);
    bgIndicator.setTargetKeyFrame(0);
    optionsGroup.addActor(bgIndicator);

    bgVolumeSet = new Slider(0f, 1f, 0.1f, false, skin);
    bgVolumeSet.setValue(bgVolValue);
    bgVolumeSet.setPosition(319f, 190f);
    bgVolumeSet.setSize(500f, 20f);
    optionsGroup.addActor(bgVolumeSet);
    bgDataSaver = new IDataSaver() {
        @Override
        public void updatePreferences(Preferences prefs) {
            prefs.putFloat(GameOptions.BG_MUSIC_VOLUME_PREF_KEY, bgVolumeSet.getValue());
        }
    };

    bgVolumeSet.addListener(new ChangeListener() {
        public void changed(ChangeEvent event, Actor actor) {
            gameProcessor.saveGameData(bgDataSaver);
            gameProcessor.setBGMusicVolume(bgVolumeSet.getValue());
        }
    });

    Animation sfxAni = new Animation(1f, atlas.findRegions(AtlasUtil.ANI_OPTIONS_SFX));
    sfxIndicator = new AnimatedActor(SFX_X, SFX_Y, SFX_W, SFX_H, sfxAni, 0f);
    sfxIndicator.setTargetKeyFrame(0);
    optionsGroup.addActor(sfxIndicator);

    sfxVolumeSet = new Slider(0f, 1f, 0.1f, false, skin);
    sfxVolumeSet.setValue(sfxVolValue);
    sfxVolumeSet.setPosition(208f, 68f);
    sfxVolumeSet.setSize(500f, 20f);
    optionsGroup.addActor(sfxVolumeSet);
    sfxDataSaver = new IDataSaver() {
        @Override
        public void updatePreferences(Preferences prefs) {
            prefs.putFloat(GameOptions.SFX_MUSIC_VOLUME_PREF_KEY, sfxVolumeSet.getValue());
        }
    };

    sfxVolumeSet.addListener(new ChangeListener() {
        public void changed(ChangeEvent event, Actor actor) {
            gameProcessor.saveGameData(sfxDataSaver);
            sfx.play(sfxVolumeSet.getValue());
        }
    });

    selectCharacter(edynSelect.isChecked());

    TextButton.TextButtonStyle style = new TextButton.TextButtonStyle();
    style.font = gameProcessor.getAssetManager().get(AssetsUtil.NEUROPOL_32, AssetsUtil.BITMAP_FONT);
    style.fontColor = Color.CYAN;

    TextButton credits = new TextButton("BG Music By DST under Creative Commons License", style);

    credits.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            Gdx.net.openURI("http://creativecommons.org/licenses/by/3.0/legalcode");
            Gdx.net.openURI("http://www.nosoapradio.us/");
        }
    });
    credits.setPosition(optionsGroup.getWidth() / 2 - (credits.getWidth() / 2), 0f);
    optionsGroup.addActor(credits);
}

From source file:com.kasetagen.game.bubblerunner.screen.BubbleRunnerMenu.java

License:Creative Commons License

private void assembleHighScoreView(TextureAtlas atlas) {
    GenericActor highScoreScaffold = new GenericActor(0f, 0f, stage.getWidth(), stage.getHeight(),
            atlas.findRegion(AtlasUtil.ANI_HIGH_SCORE_BG), Color.BLACK);
    highScoreGroup.addActor(highScoreScaffold);

    /*//from  ww w  .j a  v a2s.com
     * Add Labels
     */
    Label.LabelStyle style = new Label.LabelStyle();
    style.font = gameProcessor.getAssetManager().get(AssetsUtil.NEUROPOL_64, AssetsUtil.BITMAP_FONT);
    highScoreLabel = new Label("High Score: " + UIUtil.convertIntToDigitsString(GameStats.MAX_SCORE_DIGITS, 0),
            style);
    highComboLabel = new Label("High Combo: " + UIUtil.convertIntToDigitsString(GameStats.MAX_COMBO_DIGITS, 0),
            style);
    adjustHighScores(scoreValue, comboValue);
    highScoreGroup.addActor(highScoreLabel);
    highScoreGroup.addActor(highComboLabel);

    /*
     * Add Clear Button
     */
    TextButton.TextButtonStyle tbStyle = new TextButton.TextButtonStyle();
    tbStyle.font = gameProcessor.getAssetManager().get(AssetsUtil.NEUROPOL_64, AssetsUtil.BITMAP_FONT);
    tbStyle.fontColor = Color.WHITE;
    tbStyle.downFontColor = Color.CYAN;
    float tbXPadding = 100f;
    float tbYPadding = 50f;
    clearScoresButton = new TextButton("Clear Scores", tbStyle);
    clearScoresButton.addListener(new ClickListener() {
        IDataSaver scoreClearer = new IDataSaver() {
            @Override
            public void updatePreferences(Preferences preferences) {
                preferences.putInteger(GameStats.HIGH_SCORE_KEY, 0);
                preferences.putInteger(GameStats.HIGH_COMBO_KEY, 0);
                preferences.putInteger(GameStats.MOST_MISSES_KEY, 0);
            }
        };

        @Override
        public void clicked(InputEvent event, float x, float y) {
            gameProcessor.saveGameData(scoreClearer);
            adjustHighScores(0, 0);
        }
    });
    clearScoresButton.setPosition(tbXPadding, tbYPadding);
    highScoreGroup.addActor(clearScoresButton);

    /*
    * Add Main Menu Button
    */
    Array<TextureAtlas.AtlasRegion> mmImgs = atlas.findRegions(AtlasUtil.ANI_OPTIONS_MAINMENU);
    TextureRegionDrawable mmDown = new TextureRegionDrawable(mmImgs.get(1));
    closeScoresButton = new TextButton("Main Menu", tbStyle);
    //closeScoresButton.setSize(300f, 100f);
    closeScoresButton.setPosition(highScoreGroup.getWidth() - (closeScoresButton.getWidth() + tbXPadding),
            tbYPadding);
    closeScoresButton.addListener(listener);
    highScoreGroup.addActor(closeScoresButton);
}