Java Code Examples for com.badlogic.gdx.scenes.scene2d.ui.Image#setSize()
The following examples show how to use
com.badlogic.gdx.scenes.scene2d.ui.Image#setSize() .
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: NodeStage.java From talos with Apache License 2.0 | 5 votes |
private void initActors() { GridRenderer gridRenderer = new GridRenderer(stage); stage.addActor(gridRenderer); moduleBoardWidget = new ModuleBoardWidget(this); stage.addActor(moduleBoardWidget); selectionRect = new Image(skin.getDrawable("orange_row")); selectionRect.setSize(0, 0); selectionRect.setVisible(false); stage.addActor(selectionRect); }
Example 2
Source File: ViewController.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
private void addBackgroundObject(boolean anywhere) { final Image image = new Image(backgroundDrawables.random()); backgroundLayer.addActor(image); float scale = 0.5f * MathUtils.random(1, 2); image.setSize(image.getPrefWidth() * scale, image.getPrefHeight() * scale); image.setRotation(MathUtils.random(0, 1) * 180); image.getColor().a = MathUtils.random(0.1f, 0.3f); float w = Math.max(world.stage.getWidth(), root.getWidth() + ViewScroller.LEFT + ViewScroller.RIGHT); float h = Math.max(world.stage.getHeight(), root.getHeight() + ViewScroller.TOP + ViewScroller.BOTTOM); if (anywhere) image.setPosition(-root.getX() + w * MathUtils.random(), -root.getY() + h * MathUtils.random()); else image.setPosition(-root.getX() - image.getWidth(), -root.getY() + h * MathUtils.random()); image.addAction(Actions.sequence( Actions.moveBy(w + image.getWidth() - image.getX(), 0, 15 + MathUtils.random(6)), Actions.run(new Runnable() { @Override public void run() { image.remove(); addBackgroundObject(false); } }) )); }
Example 3
Source File: MessageTests.java From gdx-ai with Apache License 2.0 | 5 votes |
@Override public void create () { Gdx.gl.glClearColor(.3f, .3f, .3f, 1); skin = new Skin(Gdx.files.internal("data/uiskin.json")); stage = new Stage(); stage.setDebugAll(DEBUG_STAGE); stageWidth = stage.getWidth(); stageHeight = stage.getHeight(); Gdx.input.setInputProcessor(stage); // Add translucent panel (it's only visible when AI is paused) final Image translucentPanel = new Image(skin, "translucent"); translucentPanel.setSize(stageWidth, stageHeight); translucentPanel.setVisible(false); stage.addActor(translucentPanel); // Create test selection window List<String> testList = createTestList(); testSelectionWindow = addTestSelectionWindow("Tests", testList, 0, -1); // Create status bar Table statusBar = new Table(skin); statusBar.left().bottom(); statusBar.row().height(26); statusBar.add(pauseButton = new PauseButton(translucentPanel, skin)).width(90).left(); statusBar.add(new FpsLabel("FPS: ", skin)).padLeft(15); statusBar.add(testDescriptionLabel = new Label("", skin)).padLeft(15); stage.addActor(statusBar); // Set selected behavior changeTest(0); }
Example 4
Source File: BattleEventHandler.java From Unlucky with MIT License | 4 votes |
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 5
Source File: DialogScreen.java From Unlucky with MIT License | 4 votes |
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 6
Source File: SettingsScreen.java From Unlucky with MIT License | 4 votes |
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 7
Source File: MainMenuScreen.java From Bomberman_libGdx with MIT License | 4 votes |
@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 8
Source File: SteeringBehaviorsTest.java From gdx-ai with Apache License 2.0 | 4 votes |
@Override public void create () { Gdx.gl.glClearColor(.3f, .3f, .3f, 1); greenFish = new TextureRegion(new Texture("data/green_fish.png")); cloud = new TextureRegion(new Texture("data/particle-cloud.png")); badlogicSmall = new TextureRegion(new Texture("data/badlogicsmall.jpg")); target = new TextureRegion(new Texture("data/target.png")); skin = new Skin(Gdx.files.internal("data/uiskin.json")); stage = new Stage(); stage.setDebugAll(DEBUG_STAGE); stageWidth = stage.getWidth(); stageHeight = stage.getHeight(); Gdx.input.setInputProcessor(new InputMultiplexer(stage)); // Add translucent panel (it's only visible when AI is paused) final Image translucentPanel = new Image(skin, "translucent"); translucentPanel.setSize(stageWidth, stageHeight); translucentPanel.setVisible(false); stage.addActor(translucentPanel); // Create test selection window Array<List<String>> engineTests = new Array<List<String>>(); for (int k = 0; k < tests.length; k++) { engineTests.add(createTestList(k)); } testSelectionWindow = addTestSelectionWindow("Behaviors", ENGINES, engineTests, 0, -1); // Create status bar Table statusBar = new Table(skin); statusBar.left().bottom(); statusBar.row().height(26); statusBar.add(pauseButton = new PauseButton(translucentPanel, skin)).width(90).left(); statusBar.add(new FpsLabel("FPS: ", skin)).padLeft(15); statusBar.add(testHelpLabel = new Label("", skin)).padLeft(15); stage.addActor(statusBar); // Set selected behavior changeTest(0, 0); }
Example 9
Source File: ParallelVsSequenceTest.java From gdx-ai with Apache License 2.0 | 4 votes |
public TestScreen (final ParallelVsSequenceTest test, Skin skin) { this.test = test; this.skin = skin; lastUpdateTime = 0; gameOver = false; greenFishTextureRegion = new TextureRegion(new Texture("data/green_fish.png")); badlogicTextureRegion = new TextureRegion(new Texture("data/badlogicsmall.jpg")); targetTextureRegion = new TextureRegion(new Texture("data/target.png")); shapeRenderer = new ShapeRenderer(); stage = new Stage(); Stack testStack = new Stack(); stage.addActor(testStack); // Add translucent panel (it's only visible when AI is paused) final Image translucentPanel = new Image(skin, "translucent"); translucentPanel.setSize(stage.getWidth(), stage.getHeight()); translucentPanel.setVisible(false); stage.addActor(translucentPanel); // Create status bar Table statusBar = new Table(skin); statusBar.left().bottom(); statusBar.row().height(26); statusBar.add(pauseButton = new PauseButton(translucentPanel, skin)).width(90).left(); statusBar.add(new FpsLabel("FPS: ", skin)).padLeft(15); statusBar.add(new IntValueLabel("Sequence (Fish): ", 0, skin) { @Override public int getValue () { return sequencePredator.score; } }).padLeft(15); statusBar.add(new IntValueLabel("Parallel (Badlogics): ", 0, skin) { @Override public int getValue () { return parallelPredator.score; } }).padLeft(15); stage.addActor(statusBar); // Add test table testStack.setSize(stage.getWidth(), stage.getHeight()); testStack.add(testTable = new Table() { @Override public void act (float delta) { float time = GdxAI.getTimepiece().getTime(); if (lastUpdateTime != time) { lastUpdateTime = time; super.act(GdxAI.getTimepiece().getDeltaTime()); } } }); testStack.layout(); this.sheeps = new Array<Sheep>(); for (int i = 0; i < 30; i++) { Sheep sheep = new Sheep(targetTextureRegion); sheep.setMaxLinearAcceleration(50); sheep.setMaxLinearSpeed(80); sheep.setMaxAngularAcceleration(10); // greater than 0 because independent facing is enabled sheep.setMaxAngularSpeed(5); Wander<Vector2> wanderSB = new Wander<Vector2>(sheep) // .setFaceEnabled(true) // We want to use Face internally (independent facing is on) .setAlignTolerance(0.001f) // Used by Face .setDecelerationRadius(5) // Used by Face .setTimeToTarget(0.1f) // Used by Face .setWanderOffset(90) // .setWanderOrientation(10) // .setWanderRadius(40) // .setWanderRate(MathUtils.PI2 * 4); sheep.setSteeringBehavior(wanderSB); setRandomNonOverlappingPosition(sheep, sheeps, 5); setRandomOrientation(sheep); testTable.addActor(sheep); sheeps.add(sheep); } sequencePredator = createPredator(false); parallelPredator = createPredator(true); // Create GameOver panel gameOverButton = new TextButton("Game Over", skin); gameOverButton.setVisible(false); gameOverButton.addListener(new ChangeListener() { @Override public void changed (ChangeEvent event, Actor actor) { test.backToPreviousScreen(); } }); testTable.add(gameOverButton); }
Example 10
Source File: ResumeVsJoinTest.java From gdx-ai with Apache License 2.0 | 4 votes |
public TestScreen (final ResumeVsJoinTest test, Skin skin) { this.test = test; this.skin = skin; lastUpdateTime = 0; gameOver = false; greenFishTextureRegion = new TextureRegion(new Texture("data/green_fish.png")); badlogicTextureRegion = new TextureRegion(new Texture("data/badlogicsmall.jpg")); targetTextureRegion = new TextureRegion(new Texture("data/target.png")); shapeRenderer = new ShapeRenderer(); stage = new Stage(); Stack testStack = new Stack(); stage.addActor(testStack); // Add translucent panel (it's only visible when AI is paused) final Image translucentPanel = new Image(skin, "translucent"); translucentPanel.setSize(stage.getWidth(), stage.getHeight()); translucentPanel.setVisible(false); stage.addActor(translucentPanel); // Create status bar Table statusBar = new Table(skin); statusBar.left().bottom(); statusBar.row().height(26); statusBar.add(pauseButton = new PauseButton(translucentPanel, skin)).width(90).left(); statusBar.add(new FpsLabel("FPS: ", skin)).padLeft(15); statusBar.add(new IntValueLabel("Resume (Fish): ", 0, skin) { @Override public int getValue () { return resumePredator.score; } }).padLeft(15); statusBar.add(new IntValueLabel("Join (Badlogics): ", 0, skin) { @Override public int getValue () { return joinPredator.score; } }).padLeft(15); stage.addActor(statusBar); // Add test table testStack.setSize(stage.getWidth(), stage.getHeight()); testStack.add(testTable = new Table() { @Override public void act (float delta) { float time = GdxAI.getTimepiece().getTime(); if (lastUpdateTime != time) { lastUpdateTime = time; super.act(GdxAI.getTimepiece().getDeltaTime()); } } }); testStack.layout(); this.sheeps = new Array<Sheep>(); for (int i = 0; i < 30; i++) { Sheep sheep = new Sheep(targetTextureRegion); sheep.setMaxLinearAcceleration(50); sheep.setMaxLinearSpeed(80); sheep.setMaxAngularAcceleration(10); // greater than 0 because independent facing is enabled sheep.setMaxAngularSpeed(5); Wander<Vector2> wanderSB = new Wander<Vector2>(sheep) // .setFaceEnabled(true) // We want to use Face internally (independent facing is on) .setAlignTolerance(0.001f) // Used by Face .setDecelerationRadius(5) // Used by Face .setTimeToTarget(0.1f) // Used by Face .setWanderOffset(90) // .setWanderOrientation(10) // .setWanderRadius(40) // .setWanderRate(MathUtils.PI2 * 4); sheep.setSteeringBehavior(wanderSB); setRandomNonOverlappingPosition(sheep, sheeps, 5); setRandomOrientation(sheep); testTable.addActor(sheep); sheeps.add(sheep); } resumePredator = createPredator(false); joinPredator = createPredator(true); // Create GameOver panel gameOverButton = new TextButton("Game Over", skin); gameOverButton.setVisible(false); gameOverButton.addListener(new ChangeListener() { @Override public void changed (ChangeEvent event, Actor actor) { test.backToPreviousScreen(); } }); testTable.add(gameOverButton); }