Java Code Examples for com.badlogic.gdx.scenes.scene2d.ui.Label#setPosition()

The following examples show how to use com.badlogic.gdx.scenes.scene2d.ui.Label#setPosition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BvBWorkspace.java    From talos with Apache License 2.0 6 votes vote down vote up
public void flyLabel (String text) {
    Label label = new Label(text, TalosMain.Instance().getSkin());
    label.setPosition(getWidth()/2f - label.getPrefWidth()/2f, 0);
    addActor(label);

    label.addAction(Actions.fadeOut(0.4f));

    label.addAction(Actions.sequence(
            Actions.moveBy(0, 100, 0.5f),
            Actions.run(new Runnable() {
                @Override
                public void run () {
                    label.remove();
                }
            })
    ));


}
 
Example 2
Source File: ShareScoreScreen.java    From Klooni1010 with GNU General Public License v3.0 6 votes vote down vote up
ShareScoreScreen(final Klooni game, final Screen lastScreen,
                 final int score, final boolean timeMode) {
    this.game = game;
    this.lastScreen = lastScreen;

    this.score = score;
    this.timeMode = timeMode;

    final Label.LabelStyle labelStyle = new Label.LabelStyle();
    labelStyle.font = game.skin.getFont("font_small");

    infoLabel = new Label("Generating image...", labelStyle);
    infoLabel.setColor(Klooni.theme.textColor);
    infoLabel.setAlignment(Align.center);
    infoLabel.layout();
    infoLabel.setPosition(
            (Gdx.graphics.getWidth() - infoLabel.getWidth()) * 0.5f,
            (Gdx.graphics.getHeight() - infoLabel.getHeight()) * 0.5f);

    spriteBatch = new SpriteBatch();
}
 
Example 3
Source File: GameOverScreen.java    From Bomberman_libGdx with MIT License 6 votes vote down vote up
@Override
public void show() {
    viewport = new FitViewport(640, 480);
    stage = new Stage(viewport, batch);

    font = new BitmapFont(Gdx.files.internal("fonts/foo.fnt"));

    Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.WHITE);
    Label gameOverLabel = new Label("Game Over", labelStyle);
    gameOverLabel.setPosition((640 - gameOverLabel.getWidth()) / 2, 226f);

    GameManager.getInstance().playMusic("GameOver.ogg", false);

    stage.addActor(gameOverLabel);

    stage.addAction(Actions.sequence(
            Actions.delay(1f),
            Actions.fadeOut(2f),
            Actions.run(new Runnable() {
                @Override
                public void run() {
                    game.setScreen(new MainMenuScreen(game));
                }
            })));

}
 
Example 4
Source File: CardViewSmall.java    From Cardshifter with Apache License 2.0 5 votes vote down vote up
@Override
public void set(Object key, Object value) {
    if ("HEALTH".equals(key)) {
        Integer health = (Integer) value;
        Integer oldHealth = (Integer) properties.get(key);
        int diff = health - oldHealth;
        WidgetGroup grp = (WidgetGroup) table.getParent();
        grp.layout();
        
        if (diff != 0) {
            Vector2 pos = new Vector2(table.getWidth() / 2, table.getHeight() / 2);
            table.localToStageCoordinates(pos);
            final Label changeLabel = new Label(String.valueOf(diff), context.getSkin());
            Gdx.app.log("Anim", "Create health animation at " + pos.x + ", " + pos.y);
            changeLabel.setPosition(pos.x, pos.y);
            if (diff > 0) {
            	changeLabel.setColor(Color.GREEN);
            } else {
            	changeLabel.setColor(Color.RED);
            }
            changeLabel.addAction(Actions.sequence(Actions.moveBy(0, this.screenHeight/8, 1.5f), Actions.run(new Runnable() {
                @Override
                public void run() {
                    changeLabel.remove();
                }
            })));
            context.getStage().addActor(changeLabel);
        }
    }
    properties.put((String) key, value);
    cost.update(properties);
    stats.update(properties);
}
 
Example 5
Source File: FlopsyScreen.java    From flopsydroid with Apache License 2.0 5 votes vote down vote up
public void addScoreLabel() {
    mScoreLabel = new Label("0", mLabelStyle);
    mScoreLabel.setPosition(
            mStage.getViewport().getViewportWidth() / 2 - mScoreLabel.getWidth() / 2,
            mStage.getViewport().getViewportHeight() - mScoreLabel.getHeight());
    mStage.addActor(mScoreLabel);
}
 
Example 6
Source File: MenuScreen.java    From Unlucky with MIT License 5 votes vote down vote up
public MenuScreen(final Unlucky game, final ResourceManager rm) {
    super(game, rm);

    menuStyle = new Label.LabelStyle(rm.pixel10, new Color(79 / 255.f, 79 / 255.f, 117 / 255.f, 1));

    // one for each letter
    titleMoves = new Moving[7];
    letters = new Image[7];
    for (int i = 0; i < 7; i++) {
        titleMoves[i] = new Moving(new Vector2(), new Vector2(), 0);
        letters[i] = new Image(rm.title[i]);
        stage.addActor(letters[i]);
    }

    handlePlayButton();
    handleOptionButtons();

    battleLabel = new Label("Battle", menuStyle);
    battleLabel.setSize(80, 40);
    battleLabel.setFontScale(1.5f);
    battleLabel.setTouchable(Touchable.disabled);
    battleLabel.setAlignment(Align.center);
    battleLabel.setPosition(60, 35);

    stage.addActor(battleLabel);

    createCreditsScreen();

    // menu music
    rm.menuTheme.setLooping(true);
    rm.menuTheme.play();
}
 
Example 7
Source File: LegacyCompareTest.java    From talos with Apache License 2.0 5 votes vote down vote up
private void addNextEffect () {
	stage.clear();
	LegacyActor legacyActor = new LegacyActor(Gdx.files.absolute(legacyList.get(index)), atlas);
	legacyActor.setPosition(stage.getWidth() / 2f - 3f, stage.getHeight() / 2f);
	stage.addActor(legacyActor);

	TalosActor talosActor = new TalosActor(Gdx.files.absolute(talosList.get(index)), atlas, talosRenderer);
	talosActor.setPosition(stage.getWidth() / 2f + 3f, stage.getHeight() / 2f);
	stage.addActor(talosActor);

	String leftName = legacyList.get(index).substring(legacyList.get(index).lastIndexOf("/") + 1);

	uiStage.clear();
	Label mainLbl = new Label(leftName, skin);
	mainLbl.setPosition(uiStage.getWidth() / 2f - mainLbl.getPrefWidth() / 2f, 100);
	uiStage.addActor(mainLbl);

	leftTime = new Label("", skin);
	rightTime = new Label("", skin);
	comparedTime = new Label("", skin);

	leftTime.setPosition(uiStage.getWidth() / 2f - 200, 200);
	rightTime.setPosition(uiStage.getWidth() / 2f + 200, 200);
	comparedTime.setPosition(uiStage.getWidth() / 2f, 200);

	uiStage.addActor(leftTime);
	uiStage.addActor(rightTime);
	uiStage.addActor(comparedTime);

	index++;
}
 
Example 8
Source File: StageTest.java    From libgdx-inGameConsole with Apache License 2.0 5 votes vote down vote up
@Override public void create () {
	stage = new Stage();
	Gdx.input.setInputProcessor(stage);

	Skin skin = new Skin(Gdx.files.classpath("tests/test_skin/uiskin.json"));
	console = new GUIConsole(skin);
	console.setCommandExecutor(new MyCommandExecutor());
	console.setSizePercent(100, 50);

	stage.addListener(new InputListener() {
		@Override public boolean keyDown (InputEvent event, int keycode) {
			if (keycode == Input.Keys.F) {
				blink();
				return true;
			} else if (keycode == Input.Keys.TAB) {
				console.select();
				return true;
			} else if (keycode == Input.Keys.D) {
				System.out.println("Console " + (console.isDisabled() ? "enabled" : "disabled"));
				console.setDisabled(!console.isDisabled());
				return true;
			}
			return false;
		}
	});

	image = new Image(new Texture(Gdx.files.classpath("tests/badlogic" + "" + ".jpg")));
	image.setScale(.5f);
	stage.addActor(image);

	selectLabel = new Label("Select", skin);
	deselectLabel = new Label("Deselect", skin);
	stage.addActor(selectLabel);
	stage.addActor(deselectLabel);
	int padding = 25;
	selectLabel.setPosition(Gdx.graphics.getWidth() - selectLabel.getWidth() - deselectLabel.getWidth() - 2 * padding,
		selectLabel.getHeight());
	deselectLabel.setPosition(Gdx.graphics.getWidth() - deselectLabel.getWidth() - padding, deselectLabel.getHeight());
}
 
Example 9
Source File: SettingsScreen.java    From Unlucky with MIT License 4 votes vote down vote up
public SettingsScreen(final Unlucky game, final ResourceManager rm) {
    super(game, rm);

    // exit button
    stage.addActor(exitButton);
    exitButton.addListener(new ClickListener() {
        public void clicked(InputEvent event, float x, float y) {
            if (!game.player.settings.muteSfx) rm.buttonclick0.play(game.player.settings.sfxVolume);
            if (inGame) {
                game.gameScreen.resetGame = false;
                setFadeScreen(game.gameScreen);
                game.gameScreen.hud.settingsDialog.show(game.gameScreen.hud.getStage());
            }
            else {
                game.menuScreen.transitionIn = 2;
                setSlideScreen(game.menuScreen, false);
            }
        }
    });

    // create title label
    banner = new Image(rm.skin, "default-slider");
    banner.setPosition(8, 102);
    banner.setSize(164, 12);
    stage.addActor(banner);

    bannerLabel = new Label("SETTINGS", rm.skin);
    bannerLabel.setStyle(new Label.LabelStyle(rm.pixel10, new Color(1, 212 / 255.f, 0, 1)));
    bannerLabel.setSize(50, 12);
    bannerLabel.setTouchable(Touchable.disabled);
    bannerLabel.setPosition(14, 102);
    bannerLabel.setAlignment(Align.left);
    stage.addActor(bannerLabel);

    bg = new Image(rm.skin, "default-slider");
    bg.setPosition(8, 8);
    bg.setSize(184, 88);
    stage.addActor(bg);

    white = new Label.LabelStyle(rm.pixel10, Color.WHITE);
    description = new Label("SOUND                                 MISC",
        new Label.LabelStyle(rm.pixel10, new Color(1, 212 / 255.f, 0, 1)));
    description.setFontScale(0.75f);
    description.setTouchable(Touchable.disabled);
    description.setPosition(14, 85);
    stage.addActor(description);

    // create settings labels
    settingLabels = new Label[7];
    String[] settingStrs = new String[] {
        "MUSIC VOLUME", "SFX VOLUME", "MUTE MUSIC:", "MUTE SFX:",
        "SHOW ENEMY LEVELS:", "WEATHER ANIMATIONS:", "SHOW FPS:"
    };
    for (int i = 0; i < 7; i++) {
        settingLabels[i] = new Label(settingStrs[i], white);
        settingLabels[i].setTouchable(Touchable.disabled);
        settingLabels[i].setFontScale(0.5f);
        stage.addActor(settingLabels[i]);
    }
    for (int i = 0; i < 2; i++) settingLabels[i].setPosition(14, 76 - i * 24);
    for (int i = 2; i < 4; i++) settingLabels[i].setPosition(14, 26 - (i - 2) * 14);
    for (int i = 4; i < 7; i++) settingLabels[i].setPosition(111, 72 - (i - 4) * 16);

    createSliders();
    createCheckboxes();
}
 
Example 10
Source File: DefaultSceneScreen.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
void showUIText(Text t) {
	// Type UI texts will show at the same time that TextManagerUI texts.

	String style = t.style == null ? "ui-text" : t.style;
	Label msg = new Label(t.str, getUI().getSkin(), style);

	msg.setWrap(true);
	msg.setAlignment(Align.center, Align.center);

	if (t.color != null)
		msg.setColor(t.color);

	msg.setSize(msg.getWidth() + DPIUtils.getMarginSize() * 2, msg.getHeight() + DPIUtils.getMarginSize() * 2);

	stage.addActor(msg);
	unprojectTmp.set(t.x, t.y, 0);
	getWorld().getSceneCamera().scene2screen(getStage().getViewport(), unprojectTmp);

	float posx, posy;

	if (t.x == TextManager.POS_CENTER) {
		posx = (getStage().getViewport().getScreenWidth() - msg.getWidth()) / 2;
	} else if (t.x == TextManager.POS_SUBTITLE) {
		posx = DPIUtils.getMarginSize();
	} else {
		posx = unprojectTmp.x;
	}

	if (t.y == TextManager.POS_CENTER) {
		posy = (getStage().getViewport().getScreenHeight() - msg.getHeight()) / 2;
	} else if (t.y == TextManager.POS_SUBTITLE) {
		posy = getStage().getViewport().getScreenHeight() - msg.getHeight() - DPIUtils.getMarginSize() * 3;
	} else {
		posy = unprojectTmp.y;
	}

	msg.setPosition(posx, posy);
	msg.getColor().a = 0;
	msg.addAction(sequence(Actions.fadeIn(0.4f, Interpolation.fade),
			Actions.delay(t.time, sequence(fadeOut(0.4f, Interpolation.fade), Actions.removeActor()))));
}
 
Example 11
Source File: Hud.java    From Bomberman_libGdx with MIT License 4 votes vote down vote up
public Hud(SpriteBatch batch, float width, float height) {
    this.batch = batch;

    AssetManager assetManager = GameManager.getInstance().getAssetManager();
    textureAtlas = assetManager.get("img/actors.pack", TextureAtlas.class);
    bombSprite = new Sprite(new TextureRegion(textureAtlas.findRegion("Bomb"), 0, 0, 16, 16));
    bombSprite.setBounds(15.0f, 11.5f, 1, 1);

    Pixmap pixmap = new Pixmap(5, 15, Pixmap.Format.RGBA8888);
    pixmap.setColor(240.0f / 255.0f, 128 / 255.0f, 0, 1.0f);
    pixmap.fill();

    bgTexture = new Texture(pixmap);

    pixmap.setColor(1, 1, 1, 1);
    pixmap.fill();
    bombTimerTexture = new Texture(pixmap);
    pixmap.dispose();

    bombTimerSprite = new Sprite(bombTimerTexture);
    bombTimerSprite.setBounds(16f, 12.5f, 3.0f, 0.2f);

    TextureRegion itemTextureRegion = textureAtlas.findRegion("Items");
    powerSprite = new Sprite(new TextureRegion(itemTextureRegion, 16 * 1, 0, 16, 16));
    powerSprite.setBounds(leftAlignment, 9.0f, 1, 1);

    speedSprite = new Sprite(new TextureRegion(itemTextureRegion, 16 * 2, 0, 16, 16));
    speedSprite.setBounds(leftAlignment, 8.0f, 1, 1);

    kickSprite = new Sprite(new TextureRegion(itemTextureRegion, 16 * 3, 0, 16, 16));
    kickSprite.setBounds(leftAlignment, 7.0f, 1, 1);

    remoteSprite = new Sprite(new TextureRegion(itemTextureRegion, 16 * 4, 0, 16, 16));
    remoteSprite.setBounds(leftAlignment, 6.0f, 1, 1);

    Array<TextureRegion> keyFrames = new Array<TextureRegion>();
    for (int i = 0; i < 5; i++) {
        keyFrames.add(new TextureRegion(textureAtlas.findRegion("Bomberman_big"), 32 * i, 0, 32, 48));
    }
    bigBombermanAnimation = new Animation(0.2f, keyFrames, Animation.PlayMode.LOOP_PINGPONG);
    bigBombermanSprite = new Sprite(bigBombermanAnimation.getKeyFrame(0));
    bigBombermanSprite.setBounds(17.5f, 0.5f, 2f, 3f);
    stateTime = 0;

    FitViewport viewport = new FitViewport(width * SCALE, height * SCALE);
    stage = new Stage(viewport, batch);
    font = new BitmapFont(Gdx.files.internal("fonts/foo.fnt"));
    Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.WHITE);
    fpsLabel = new Label("FPS:", labelStyle);
    fpsLabel.setFontScale(0.3f);
    fpsLabel.setPosition(16 * SCALE, -0.8f * SCALE);
    fpsLabel.setVisible(showFPS);
    
    levelLabel = new Label("Level", labelStyle);
    levelLabel.setPosition(15.5f * SCALE, 3 * SCALE);
    levelLabel.setFontScale(0.4f);

    playerLivesLabel = new Label("" + GameManager.playerLives, labelStyle);
    playerLivesLabel.setFontScale(0.5f);
    playerLivesLabel.setPosition(16.8f * SCALE, 12.8f * SCALE);

    Image bombermanImage = new Image(new TextureRegion(textureAtlas.findRegion("Items"), 16 * 5, 0, 16, 16));
    bombermanImage.setPosition(leftAlignment * SCALE, 13.5f * SCALE);

    xLabel = new Label("X", labelStyle);
    xLabel.setFontScale(0.4f);
    xLabel.setPosition(16.8f * SCALE, 6.3f * SCALE);

    zLabel = new Label("Z", labelStyle);
    zLabel.setFontScale(0.4f);
    zLabel.setPosition(16.8f * SCALE, 5.3f * SCALE);

    stage.addActor(fpsLabel);
    stage.addActor(levelLabel);
    stage.addActor(playerLivesLabel);
    stage.addActor(bombermanImage);
    stage.addActor(xLabel);
    stage.addActor(zLabel);
    
    stringBuilder = new StringBuilder();
    
}
 
Example 12
Source File: MainMenuScreen.java    From Bomberman_libGdx with MIT License 4 votes vote down vote up
@Override
public void show() {
    viewport = new FitViewport(640, 480);
    stage = new Stage(viewport, batch);

    font = new BitmapFont(Gdx.files.internal("fonts/foo.fnt"));

    Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.WHITE);

    Label titleLabel = new Label("Bomberman", labelStyle);
    titleLabel.setFontScale(1.6f);
    titleLabel.setPosition(140, 360);

    Label easyLabel = new Label("Easy", labelStyle);
    easyLabel.setPosition((640 - easyLabel.getWidth()) / 2, 240);

    Label normalLabel = new Label("Normal", labelStyle);
    normalLabel.setPosition((640 - normalLabel.getWidth()) / 2, 180);

    Label hardLabel = new Label("Hard", labelStyle);
    hardLabel.setPosition((640 - hardLabel.getWidth()) / 2, 120);

    Pixmap pixmap = new Pixmap(640, 480, Pixmap.Format.RGB888);
    pixmap.setColor(240.0f / 255.0f, 128 / 255.0f, 0, 1.0f);
    pixmap.fill();
    backgroundTexture = new Texture(pixmap);
    pixmap.dispose();
    Image background = new Image(backgroundTexture);

    indicatorX = 160f;
    indicatorY = 240f;

    TextureAtlas textureAtlas = GameManager.getInstance().getAssetManager().get("img/actors.pack", TextureAtlas.class);
    indicator0 = new Image(new TextureRegion(textureAtlas.findRegion("MainMenuLogo"), 0, 0, 40, 26));
    indicator0.setSize(80f, 52f);
    indicator0.setPosition(indicatorX, indicatorY);

    indicator1 = new Image(new TextureRegion(textureAtlas.findRegion("MainMenuLogo"), 40, 0, 40, 26));
    indicator1.setSize(80f, 52f);
    indicator1.setPosition(indicatorX, indicatorY);
    indicator1.setVisible(false);
    
    indicationsTexture = new Texture("img/indications.png");
    indications = new Image(indicationsTexture);
    indications.setPosition(640f - indications.getWidth() - 12f, 12f);

    stage.addActor(background);
    stage.addActor(indications);
    stage.addActor(titleLabel);
    stage.addActor(easyLabel);
    stage.addActor(normalLabel);
    stage.addActor(hardLabel);
    stage.addActor(indicator0);
    stage.addActor(indicator1);

    currentSelection = 0;
    selected = false;
    
    GameManager.getInstance().playMusic("SuperBomberman-Title.ogg", true);
}
 
Example 13
Source File: PlayScreen.java    From Pacman_libGdx with MIT License 4 votes vote down vote up
@Override
public void show() {
    camera = new OrthographicCamera();
    viewport = new FitViewport(WIDTH, HEIGHT, camera);
    camera.translate(WIDTH / 2, HEIGHT / 2);
    camera.update();

    batch = new SpriteBatch();

    playerSystem = new PlayerSystem();
    ghostSystem = new GhostSystem();
    movementSystem = new MovementSystem();
    pillSystem = new PillSystem();
    animationSystem = new AnimationSystem();
    renderSystem = new RenderSystem(batch);
    stateSystem = new StateSystem();

    engine = new Engine();
    engine.addSystem(playerSystem);
    engine.addSystem(ghostSystem);
    engine.addSystem(pillSystem);
    engine.addSystem(movementSystem);
    engine.addSystem(stateSystem);
    engine.addSystem(animationSystem);
    engine.addSystem(renderSystem);

    // box2d
    world = new World(Vector2.Zero, true);
    world.setContactListener(new WorldContactListener());
    box2DDebugRenderer = new Box2DDebugRenderer();
    showBox2DDebuggerRenderer = false;

    // box2d light
    rayHandler = new RayHandler(world);
    rayHandler.setAmbientLight(ambientLight);

    // load map
    tiledMap = new TmxMapLoader().load("map/map.tmx");
    tiledMapRenderer = new OrthogonalTiledMapRenderer(tiledMap, 1 / 16f, batch);

    new WorldBuilder(tiledMap, engine, world, rayHandler).buildAll();

    stageViewport = new FitViewport(WIDTH * 20, HEIGHT * 20);
    stage = new Stage(stageViewport, batch);

    font = new BitmapFont(Gdx.files.internal("fonts/army_stencil.fnt"));
    Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.WHITE);

    Label scoreTextLabel = new Label("SCORE", labelStyle);
    scoreTextLabel.setPosition(WIDTH * 1, HEIGHT * 19);
    stage.addActor(scoreTextLabel);

    Label hightScoreTextLabel = new Label("High Score", labelStyle);
    hightScoreTextLabel.setPosition(WIDTH * 14, HEIGHT * 19);
    stage.addActor(hightScoreTextLabel);

    scoreLabel = new Label("0", labelStyle);
    scoreLabel.setPosition(WIDTH * 1.5f, HEIGHT * 18.2f);
    stage.addActor(scoreLabel);

    highScoreLabel = new Label("0", labelStyle);
    highScoreLabel.setPosition(WIDTH * 16.5f, HEIGHT * 18.2f);
    stage.addActor(highScoreLabel);

    gameOverLabel = new Label("              - Game Over -\n Press Enter to continue", labelStyle);
    gameOverLabel.setPosition(WIDTH * 4.3f, HEIGHT * 9f);
    gameOverLabel.setVisible(false);
    stage.addActor(gameOverLabel);

    TextureAtlas textureAtlas = GameManager.instance.assetManager.get("images/actors.pack", TextureAtlas.class);
    pacmanSprite = new Sprite(new TextureRegion(textureAtlas.findRegion("Pacman"), 16, 0, 16, 16));
    pacmanSprite.setBounds(8f, 21.5f, 16 / GameManager.PPM, 16 / GameManager.PPM);

    stringBuilder = new StringBuilder();

    changeScreen = false;
}
 
Example 14
Source File: DialogScreen.java    From Unlucky with MIT License 4 votes vote down vote up
public DialogScreen(GameScreen gameScreen, TileMap tileMap, Player player, final ResourceManager rm) {
    super(gameScreen, tileMap, player, rm);

    // create main UI
    ui = new Image(rm.dialogBox400x80);
    ui.setSize(200, 40);
    ui.setPosition(0, 0);
    ui.setTouchable(Touchable.disabled);

    stage.addActor(ui);

    // create Labels
    BitmapFont bitmapFont = rm.pixel10;
    Label.LabelStyle font = new Label.LabelStyle(bitmapFont, new Color(0, 0, 0, 255));

    textLabel = new Label("", font);
    textLabel.setWrap(true);
    textLabel.setTouchable(Touchable.disabled);
    textLabel.setFontScale(1.7f / 2);
    textLabel.setPosition(8, 6);
    textLabel.setSize(350 / 2, 52 / 2);
    textLabel.setAlignment(Align.topLeft);
    stage.addActor(textLabel);

    clickLabel = new Label("", font);
    clickLabel.setSize(200, 120);
    clickLabel.setPosition(0, 0);

    final Player p = player;
    clickLabel.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (dialogIndex + 1 == currentDialog.length && endCycle) {
                if (!p.settings.muteSfx) rm.textprogression.play(p.settings.sfxVolume);
                // the text animation has run through every element of the text array
                endDialog();
                handleEvent(nextEvent);
            }
            // after a cycle of text animation ends, clicking the UI goes to the next cycle
            else if (endCycle && dialogIndex < currentDialog.length) {
                if (!p.settings.muteSfx) rm.textprogression.play(p.settings.sfxVolume);
                dialogIndex++;
                reset();
                currentText = currentDialog[dialogIndex];
                anim = currentText.split("");
                beginCycle = true;
            }
            // clicking on the box during a text animation completes it early
            else if (beginCycle && !endCycle) {
                resultingText = currentText;
                textLabel.setText(resultingText);
                beginCycle = false;
                endCycle = true;
            }
        }
    });
    stage.addActor(clickLabel);
}
 
Example 15
Source File: LevelUpScreen.java    From Unlucky with MIT License 4 votes vote down vote up
public LevelUpScreen(GameScreen gameScreen, TileMap tileMap, Player player, ResourceManager rm) {
    super(gameScreen, tileMap, player, rm);

    // create bg
    ImageButton.ImageButtonStyle style = new ImageButton.ImageButtonStyle();
    style.imageUp = new TextureRegionDrawable(rm.levelupscreen400x240);
    ui = new ImageButton(style);
    ui.setSize(200, 120);
    ui.setPosition(0, 0);
    ui.setTouchable(Touchable.disabled);
    stage.addActor(ui);

    handleClick();

    // create animation
    levelUpAnim = new AnimationManager(rm.levelUp96x96, 4, 0, 1 / 4f);

    // create labels
    BitmapFont font = rm.pixel10;
    Label.LabelStyle titleFont = new Label.LabelStyle(font, new Color(0, 205 / 255.f, 20 / 255.f, 1));
    Label.LabelStyle stdWhite = new Label.LabelStyle(font, new Color(1, 1, 1, 1));
    Label.LabelStyle yellow = new Label.LabelStyle(font, new Color(1, 212 / 255.f, 0, 1));
    Label.LabelStyle blue = new Label.LabelStyle(font, new Color(0, 190 / 255.f, 1, 1));

    title = new Label("LEVEL UP!", titleFont);
    title.setSize(200, 20);
    title.setPosition(0, 95);
    title.setFontScale(2.5f);
    title.setAlignment(Align.center);
    title.setTouchable(Touchable.disabled);
    stage.addActor(title);

    levelDesc = new Label("You reached level 1", stdWhite);
    levelDesc.setSize(200, 20);
    levelDesc.setPosition(0, 80);
    levelDesc.setAlignment(Align.center);
    levelDesc.setTouchable(Touchable.disabled);
    stage.addActor(levelDesc);

    statsDescs = new Label[statNames.length];
    stats = new Label[statNames.length];
    increases = new Label[statNames.length];

    for (int i = 0; i < statNames.length; i++) {
        statsDescs[i] = new Label(statNames[i], stdWhite);
        statsDescs[i].setSize(10, 10);
        statsDescs[i].setFontScale(1.3f / 2);
        statsDescs[i].setPosition(100, 17 + (i * 12));
        statsDescs[i].setAlignment(Align.left);
        statsDescs[i].setTouchable(Touchable.disabled);
        stage.addActor(statsDescs[i]);

        stats[i] = new Label("1330", blue);
        stats[i].setSize(10, 10);
        stats[i].setFontScale(1.3f / 2);
        stats[i].setPosition(140, 17 + (i * 12));
        stats[i].setAlignment(Align.left);
        stats[i].setTouchable(Touchable.disabled);
        stage.addActor(stats[i]);

        increases[i] = new Label("+20", yellow);
        increases[i].setSize(10, 10);
        increases[i].setFontScale(1.3f / 2);
        increases[i].setPosition(170, 17 + (i * 12));
        increases[i].setAlignment(Align.left);
        increases[i].setTouchable(Touchable.disabled);
        stage.addActor(increases[i]);
    }

    clickToContinue = new Label("Click to continue", stdWhite);
    clickToContinue.setSize(200, 10);
    clickToContinue.setFontScale(0.5f);
    clickToContinue.setPosition(0, 2);
    clickToContinue.setAlignment(Align.center);
    clickToContinue.setTouchable(Touchable.disabled);
    stage.addActor(clickToContinue);
}
 
Example 16
Source File: BattleEventHandler.java    From Unlucky with MIT License 4 votes vote down vote up
public BattleEventHandler(GameScreen gameScreen, TileMap tileMap, Player player, Battle battle,
                          BattleUIHandler uiHandler, Stage stage, final ResourceManager rm) {
    super(gameScreen, tileMap, player, battle, uiHandler, rm);

    this.stage = stage;

    // create main UI
    ui = new Image(rm.dialogBox400x80);
    ui.setSize(200, 40);
    ui.setPosition(0, 0);
    ui.setTouchable(Touchable.disabled);

    stage.addActor(ui);

    // create Labels
    BitmapFont bitmapFont = rm.pixel10;
    Label.LabelStyle font = new Label.LabelStyle(bitmapFont, new Color(0, 0, 0, 255));

    textLabel = new Label("", font);
    textLabel.setWrap(true);
    textLabel.setTouchable(Touchable.disabled);
    textLabel.setFontScale(1.7f / 2);
    textLabel.setPosition(8, 6);
    textLabel.setSize(175, 26);
    textLabel.setAlignment(Align.topLeft);
    stage.addActor(textLabel);

    clickLabel = new Label("", font);
    clickLabel.setSize(200, 120);
    clickLabel.setPosition(0, 0);

    final Player p = player;
    clickLabel.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (dialogIndex + 1 == currentDialog.length && endCycle) {
                if (!p.settings.muteSfx) rm.textprogression.play(p.settings.sfxVolume);
                // the text animation has run through every element of the text array
                endDialog();
                handleBattleEvent(nextEvent);
            }
            // after a cycle of text animation ends, clicking the UI goes to the next cycle
            else if (endCycle && dialogIndex < currentDialog.length) {
                if (!p.settings.muteSfx) rm.textprogression.play(p.settings.sfxVolume);
                dialogIndex++;
                reset();
                currentText = currentDialog[dialogIndex];
                anim = currentText.split("");
                beginCycle = true;
            }
            // clicking on the box during a text animation completes it early
            else if (beginCycle && !endCycle) {
                resultingText = currentText;
                textLabel.setText(resultingText);
                beginCycle = false;
                endCycle = true;
            }
        }
    });
    stage.addActor(clickLabel);
}
 
Example 17
Source File: ShareChallenge.java    From Klooni1010 with GNU General Public License v3.0 4 votes vote down vote up
public boolean saveChallengeImage(final int score, final boolean timeMode) {
    final File saveAt = getShareImageFilePath();
    if (!saveAt.getParentFile().isDirectory())
        if (!saveAt.mkdirs())
            return false;

    final FileHandle output = new FileHandle(saveAt);

    final Texture shareBase = new Texture(Gdx.files.internal("share.png"));
    final int width = shareBase.getWidth();
    final int height = shareBase.getHeight();

    final FrameBuffer frameBuffer = new FrameBuffer(Pixmap.Format.RGB888, width, height, false);
    frameBuffer.begin();

    // Render the base share texture
    final SpriteBatch batch = new SpriteBatch();
    final Matrix4 matrix = new Matrix4();
    matrix.setToOrtho2D(0, 0, width, height);
    batch.setProjectionMatrix(matrix);

    Gdx.gl.glClearColor(Color.GOLD.r, Color.GOLD.g, Color.GOLD.b, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    batch.begin();
    batch.draw(shareBase, 0, 0);

    // Render the achieved score
    final Label.LabelStyle style = new Label.LabelStyle();
    style.font = new BitmapFont(Gdx.files.internal("font/x1.0/geosans-light64.fnt"));
    Label label = new Label("just scored " + score + " on", style);
    label.setColor(Color.BLACK);
    label.setPosition(40, 500);
    label.draw(batch, 1);

    label.setText("try to beat me if you can");
    label.setPosition(40, 40);
    label.draw(batch, 1);

    if (timeMode) {
        Texture timeModeTexture = new Texture("ui/x1.5/stopwatch.png");
        batch.setColor(Color.BLACK);
        batch.draw(timeModeTexture, 200, 340);
    }

    batch.end();

    // Get the framebuffer pixels and write them to a local file
    final byte[] pixels = ScreenUtils.getFrameBufferPixels(0, 0, width, height, true);

    final Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.RGBA8888);

    BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length);
    PixmapIO.writePNG(output, pixmap);

    // Dispose everything
    pixmap.dispose();
    shareBase.dispose();
    batch.dispose();
    frameBuffer.end();

    return true;
}
 
Example 18
Source File: Main.java    From graphicsfuzz with Apache License 2.0 4 votes vote down vote up
@Override
public void create() {

  if(this.overrideLogger != null){
    Gdx.app.setApplicationLogger(overrideLogger);
  }

  // Only DesktopLauncher sets this.
  if(gl30 == null) {
    // Gdx.gl30 could also be null though.
    gl30 = Gdx.gl30;
  }

  Gdx.graphics.getGL20().glEnable(GL20.GL_TEXTURE_2D);
  Gdx.graphics.getGL20().glEnable(GL20.GL_DEPTH_TEST);
  Gdx.graphics.getGL20().glDepthFunc(GL20.GL_LESS);

  standardMesh = buildFullScreenQuadMesh();

  if(standaloneRenderJob != null) {
    if (standaloneRenderJob.isSetComputeSource()) {
      updateState(WorkerState.COMPUTE_STANDALONE_PREPARE);
    } else {
      updateState(WorkerState.IMAGE_STANDALONE_PREPARE);
    }
    return;
  }

  PlatformInfoUtil.getPlatformDetails(platformInfoJson);
  PlatformInfoUtil.getGlVersionInfo(platformInfoJson, gl30);

  sanityReferenceImage = createPixelBuffer();
  sanityCheckImage = createPixelBuffer();
  sanityCheckImageTmp = createPixelBuffer();

  GdxStage = new Stage(new ScreenViewport());
  Label.LabelStyle label1Style = new Label.LabelStyle();
  label1Style.font = new BitmapFont();
  label1Style.fontColor = Color.WHITE;

  DisplayContent = new StringBuilder();
  DisplayLabel = new Label(DisplayContent.toString(), label1Style);
  DisplayLabel.setPosition(WIDTH + DISPLAY_TXT_MARGIN, 0);
  DisplayLabel
      .setSize(Gdx.graphics.getWidth() - WIDTH - DISPLAY_TXT_MARGIN - 10, Gdx.graphics.getHeight() - 10);
  DisplayLabel.setAlignment(Align.topLeft);
  DisplayContent = new StringBuilder();
  GdxStage.addActor(DisplayLabel);
}
 
Example 19
Source File: MainMenuInterface.java    From buffer_bci with GNU General Public License v3.0 3 votes vote down vote up
private void createStageActors() {
	faster = new CheckBox(LABEL_FASTER, skin);

	color = new CheckBox(LABEL_COLOR, skin);

	animate = new CheckBox(LABEL_ANIMATE, skin);

	sound = new CheckBox(LABEL_SOUND, skin);
	table.setPosition(210, 30);

	outline = new CheckBox(LABEL_OUTLINE, skin);

	permOutline = new CheckBox(LABEL_PERM_OUTLINE, skin);

	fasterLabel = new Label(LABEL_FASTER_SELECT, skin);
	fasterLabel.setPosition(240 - fasterLabel.getWidth() / 2, 115);

	fasterSlider = new Slider(0, 5, 1, false, skin);
	fasterSlider.setWidth(outline.getWidth());
	fasterSlider.setPosition(240 - fasterSlider.getWidth() / 2, 100);

	levelLabel = new Label(LABEL_LEVEL_SELECT, skin);
	levelLabel.setPosition(240 - levelLabel.getWidth() / 2, 85);

	levelSlider = new Slider(0, 5, 1, false, skin);
	levelSlider.setWidth(outline.getWidth());
	levelSlider.setPosition(240 - levelSlider.getWidth() / 2, 70);

	start = new TextButton("Start", skin);
	start.setPosition(210, 36);

	license = new TextButton("License", skin);
	license.setPosition(205, 2);

	fasterLabel.setY(215);
	fasterSlider.setY(200);

	levelLabel.setY(185);
	levelSlider.setY(170);
}