List of usage examples for com.badlogic.gdx.scenes.scene2d.utils Align center
int center
To view the source code for com.badlogic.gdx.scenes.scene2d.utils Align center.
Click Source Link
From source file:be.ac.ucl.lfsab1509.bouboule.game.screen.AboutScreen.java
License:Open Source License
@Override public void show() { super.show(); //Set Background addBackGroundShift("GdxMenus/settings/settingsbg.jpg"); // Note: no accent with the default font and multiple spaces or \t are not working String cAboutText = "App's name:\n" + " Bouboule\n\n" + "Authors: (v1)\n" + " Baerts Matthieu, Remy Baptiste, Van Wallendael " + "Nicolas and Verhaeghe Helene\n\n" + "Authors: (v2+)\n" + " Baerts Matthieu, Van Wallendael Nicolas\n\n" + "Graphisms:\n" + " Van Wallendael Julien\n\n" + "Music and sounds:\n" + " Adans Paschal (adanspaschal.gmail.com) and" + " Klez (The gateway - SpaceShip level)\n\n" + "Credits & License:\n" + " Bouboule was developed during the course" + " FSAB1509 - Projet Informatique (Yves Deville, Universite" + " Catholique de Louvain, Belgium), 2012-2013.\n\n" + "Open-Source GPL3 license and developed with LibGDX" + " (Free and Open-Source game development framework under" + " Apache License 2.0)."; int iVersion = Gdx.app.getVersion(); if (iVersion > 0) cAboutText += "\n\nVersion: " + iVersion; Label label = new Label(cAboutText, getSkin(), "osaka-font", Color.WHITE); // not on the border label.setWidth(GlobalSettings.APPWIDTH - 20 * GlobalSettings.HD); label.setHeight(GlobalSettings.APPHEIGHT - 20 * GlobalSettings.HD); label.setPosition(10 * GlobalSettings.HD, 10 * GlobalSettings.HD); label.setAlignment(Align.center); label.setWrap(true); // return to the next lines // filters// w ww .j a v a2 s. com // label.getStyle().font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear); // label.setFillParent(true); used all the screen: too large stage.addActor(label); //Create all Buttons addBackButton(false); }
From source file:be.ac.ucl.lfsab1509.bouboule.game.screen.GameOverScreen.java
License:Open Source License
private void showHighScore() { highScoreLabel = new Label("HIGH SCORE", getSkin(), "darktimes-font", new Color(0.309f, 0.584f, .796f, 1f)); highScoreLabel.setFontScale(.6f);/* www.j a va2 s . c om*/ highScoreLabel.setAlignment(Align.center); highScoreLabel.setWidth(GlobalSettings.APPWIDTH); highScoreLabel.setY(GlobalSettings.ISHD ? 930 : 560); highScoreLabel.setTouchable(null); // we can click through it stage.addActor(highScoreLabel); ActionHighScore highScoreAction = new ActionHighScore(); stage.addAction(highScoreAction); highScoreAction.setActor(highScoreLabel); }
From source file:be.ac.ucl.lfsab1509.bouboule.game.screen.MenuScreen.java
License:Open Source License
@Override public void show() { super.show(); // Set Background addBackGroundShift("GdxMenus/main/mainmenubg.jpg"); // Add Button image addBackGround("GdxMenus/main/mainmenubuttons.png"); // Create the 2 Bouboules out of the screen final Image imgBoubouleR = addImage("GdxMenus/main/boubouleright.png", GlobalSettings.APPWIDTH, 1f); final Image imgBoubouleL = addImage("GdxMenus/main/boubouleleft.png", -GlobalSettings.APPWIDTH, 1f); // add action on the bouboule final ActionBouboul actionbouL = new ActionBouboul(false); this.stage.addAction(actionbouL); actionbouL.setActor(imgBoubouleL);/* w ww . j ava2s . co m*/ final ActionBouboul actionbouR = new ActionBouboul(true); this.stage.addAction(actionbouR); actionbouR.setActor(imgBoubouleR); // add the title title = new Label("BOUBOULE", getSkin(), "darktimes-font", new Color(.388f, .733f, .984f, 1f)); title.setAlignment(Align.center); // center title.setWidth(GlobalSettings.APPWIDTH); // title.setColor(.2f, .7098f, .898f, 1f); // android color // add the title in a table in order to rotate it. Table tableTitle = new Table(); tableTitle.add(title); tableTitle.setTransform(true); tableTitle.setWidth(GlobalSettings.APPWIDTH); // all the width tableTitle.setX(0); tableTitle.setY((int) (1050 * GlobalSettings.HD) - GlobalSettings.SHIFT_BG_HEIGHT / 2); tableTitle.setOrigin(GlobalSettings.APPWIDTH / 2, tableTitle.getHeight() / 2); // at the center stage.addActor(tableTitle); // add action on the title final ActionTitle actiontitle = new ActionTitle(); this.stage.addAction(actiontitle); actiontitle.setActor(tableTitle); // Add 5 button transparent Button playButton, paramButton, scoreButton, boubouleButton, titleButton; if (GlobalSettings.ISHD) { playButton = createButton("transparent", 690, 250, 312, 1150); paramButton = createButton("transparent", 690, 250, 312, 887); scoreButton = createButton("transparent", 690, 250, 312, 615); boubouleButton = createButton("transparent", 1000, 600, 200, 0); titleButton = createButton("transparent", 1000, 1000, 200, 1450); } else { playButton = createButton("transparent", 430, 160, 200, 725); paramButton = createButton("transparent", 430, 160, 200, 555); scoreButton = createButton("transparent", 430, 160, 200, 385); boubouleButton = createButton("transparent", 500, 350, 200, 0); titleButton = createButton("transparent", 500, 500, 200, 885); } // Listener for the button playButton.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { if (GlobalSettings.GAME.isPlayingGame()) setScreenWithFading(null); else setScreenWithFading(new WorldScreen()); } }); paramButton.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { setScreenWithFading(new ParamScreen()); } }); scoreButton.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { if (GlobalSettings.GAMECENTER != null) { GlobalSettings.GAMECENTER.showLeaderboard(); } else { Dialog dialog = new Dialog(" HighScore ", getSkin(), "default") { // improved default skin? // protected void result(Object object) {} // Just hide the dialog }.text("\n" + getHighScoreText() + " ").button(" Close ", null).show(stage); dialog.setX((GlobalSettings.APPWIDTH - dialog.getWidth()) / 2); } } }); boubouleButton.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { final ActionBouboul actionbouL = new ActionBouboul(false); actionbouL.init(); stage.addAction(actionbouL); actionbouL.setActor(imgBoubouleL); final ActionBouboul actionbouR = new ActionBouboul(true); actionbouR.init(); stage.addAction(actionbouR); actionbouR.setActor(imgBoubouleR); } }); titleButton.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { actiontitle.switchName(); } }); }
From source file:be.ac.ucl.lfsab1509.bouboule.game.screen.UserScreen.java
License:Open Source License
private void addSoundOptions() { addLabel("SOUND", FONT_TITLE, FONT_SCALE, Color.WHITE, iX, iY).setTouchable(null); soundCheckBox = addCheckBox("Music", !GlobalSettings.SOUND_IS_MUTED, iX, iY - (GlobalSettings.ISHD ? 150 : 50)); // bigger click zone soundCheckBox.getLabelCell().align(Align.center); soundCheckBox.setHeight(soundCheckBox.getHeight() * 3); soundCheckBox.setWidth(GlobalSettings.APPWIDTH - soundCheckBox.getImage().getWidth()); // align center soundCheckBox.addListener(soundClickListener); }
From source file:be.ac.ucl.lfsab1509.bouboule.game.screen.WorldScreen.java
License:Open Source License
private void displayInfoWorlds() { if (bInfoDisplayed || GlobalSettings.PROFILE.getBestLevel() / 4 > 5) return;/*ww w . j a v a 2s . co m*/ bInfoDisplayed = true; if (infoLabel == null) { String text = "There are " + GlobalSettings.NBLEVELS / 4 + " worlds\n\n" + "To unlock the next world,\n" + "you have to win 4 fights in a row.\n" + "Click on your player to start fighting!"; infoLabel = addLabel(text, "osakaMid-font", 1f, new Color(.411f, .443f, .188f, 1f), 0, (int) (450 * GlobalSettings.HD)); infoLabel.setAlignment(Align.center); infoLabel.setWidth(GlobalSettings.APPWIDTH); infoLabel.setOrigin(GlobalSettings.APPWIDTH / 2, infoLabel.getHeight() / 2); infoLabel.setTouchable(null); } else stage.addActor(infoLabel); ActionInfo actionInfo = new ActionInfo(); this.stage.addAction(actionInfo); actionInfo.setActor(infoLabel); }
From source file:coder5560.gdxai.SteeringActor.java
License:Apache License
@Override public void act(float delta) { position.set(getX(Align.center), getY(Align.center)); if (steeringBehavior != null) { // Calculate steering acceleration steeringBehavior.calculateSteering(steeringOutput); /*/* w w w . j a v a 2s . co m*/ * Here you might want to add a motor control layer filtering * steering accelerations. * * For instance, a car in a driving game has physical constraints on * its movement: it cannot turn while stationary; the faster it * moves, the slower it can turn (without going into a skid); it can * brake much more quickly than it can accelerate; and it only moves * in the direction it is facing (ignoring power slides). */ // Apply steering acceleration if (applySteering) { applySteering(steeringOutput, delta); } wrapAround(position, getParent().getWidth(), getParent().getHeight()); setPosition(position.x, position.y, Align.center); } super.act(delta); }
From source file:com.badlogic.gdx.ai.tests.steer.scene2d.Scene2dTargetInputProcessor.java
License:Apache License
protected void setTargetPosition(int screenX, int screenY) { Vector2 pos = target.getPosition(); target.getStage().screenToStageCoordinates(pos.set(screenX, screenY)); target.getParent().stageToLocalCoordinates(pos); target.setPosition(pos.x, pos.y, Align.center); }
From source file:com.badlogic.gdx.ai.tests.steer.scene2d.SteeringActor.java
License:Apache License
@Override public void act(float delta) { position.set(getX(Align.center), getY(Align.center)); if (steeringBehavior != null) { // Calculate steering acceleration steeringBehavior.calculateSteering(steeringOutput); /*/* w w w . java 2s .c om*/ * Here you might want to add a motor control layer filtering steering accelerations. * * For instance, a car in a driving game has physical constraints on its movement: it cannot turn while stationary; the * faster it moves, the slower it can turn (without going into a skid); it can brake much more quickly than it can * accelerate; and it only moves in the direction it is facing (ignoring power slides). */ // Apply steering acceleration applySteering(steeringOutput, delta); wrapAround(position, getParent().getWidth(), getParent().getHeight()); setPosition(position.x, position.y, Align.center); } super.act(delta); }
From source file:com.badlogic.gdx.ai.tests.utils.scene2d.TabbedPane.java
License:Apache License
private void initialize() { setTouchable(Touchable.enabled);// ww w . j av a 2s .c om tabTitleTable = new Table(); tabBodyStack = new Stack(); selectedIndex = -1; // Create 1st row Cell<?> leftCell = add(new Image(style.titleBegin)); Cell<?> midCell = add(tabTitleTable); Cell<?> rightCell = add(new Image(style.titleEnd)); switch (tabTitleAlign) { case Align.left: leftCell.width(((Image) leftCell.getActor()).getWidth()).bottom(); midCell.left(); rightCell.expandX().fillX().bottom(); break; case Align.right: leftCell.expandX().fillX().bottom(); midCell.right(); rightCell.width(((Image) rightCell.getActor()).getWidth()).bottom(); break; case Align.center: leftCell.expandX().fillX().bottom(); midCell.center(); rightCell.expandX().fillX().bottom(); break; default: throw new IllegalArgumentException("TabbedPane align must be one of left, center, right"); } // Create 2nd row row(); Table t = new Table(); t.setBackground(style.bodyBackground); t.add(tabBodyStack); add(t).colspan(3).expand().fill(); }
From source file:com.badlogic.gdx.spriter.demo.SpriterDemoApp.java
@Override public void create() { // Initialize object batch = new SpriteBatch(); camera = new OrthographicCamera(); FileHandleResolver resolver = new InternalFileHandleResolver(); assetManager = new AssetManager(resolver); assetManager.setLoader(SpriterData.class, new SpriterDataLoader(resolver)); resolver = new AbsoluteFileHandleResolver(); externalAssetManager = new AssetManager(resolver); externalAssetManager.setLoader(SpriterData.class, new SpriterDataLoader(resolver)); assetManager.load("uiskin.json", Skin.class); assetManager.finishLoading();// w ww . j a v a 2s .c o m skin = assetManager.get("uiskin.json"); // Create widgets stage = new Stage(new ScreenViewport(camera), batch); Label titleLabel = new Label("gdx-spriter", skin); titleLabel.setFontScale(3f); Label fpsLabel = new Label("FPS", skin) { @Override public void act(float delta) { this.setText(Gdx.graphics.getFramesPerSecond() + " FPS"); super.act(delta); } }; fileChooser = new SelectBox<SpriterDemoFileHandle>(skin); fileChooser.setName("Files"); fileChooser.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { changeSpriterFile(fileChooser.getSelected()); lastUsedSelectBox = fileChooser; } }); Button fileFinder = new TextButton("Browse", skin); fileFinder.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { FileDialog fileDialog = new FileDialog((java.awt.Frame) null, "Choose Spriter file", FileDialog.LOAD); fileDialog.setDirectory(lastFolderBrowsed); fileDialog.setResizable(true); fileDialog.setVisible(true); String file = fileDialog.getFile(); String directory = fileDialog.getDirectory(); if (directory != null) { lastFolderBrowsed = directory; } if (file != null) { String path = directory + file; addFile(Gdx.files.absolute(path), externalAssetManager); fileChooser.setItems(files); fileChooser.setSelectedIndex(fileChooser.getItems().size - 1); } } }); entityChooser = new SelectBox<SpriterAnimator>(skin); entityChooser.setName("Entities"); entityChooser.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { changeAnimator(entityChooser.getSelected()); lastUsedSelectBox = entityChooser; } }); animationChooser = new SelectBox<String>(skin); animationChooser.setName("Animations"); animationChooser.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { changeAnimation(animationChooser.getSelected()); lastUsedSelectBox = animationChooser; } }); final CheckBox transitionCheckbox = new CheckBox("Transition", skin); transitionCheckbox.setChecked(transition); transitionCheckbox.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { transition = transitionCheckbox.isChecked(); } }); charmapChooser = new List<SpriterCharacterMap>(skin); ArraySelection<SpriterCharacterMap> selection = charmapChooser.getSelection(); selection.setMultiple(true); selection.setRangeSelect(false); selection.setToggle(false); selection.setRequired(false); charmapChooser.setName("Charmaps"); charmapChooser.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { changeCharacterMaps(charmapChooser.getSelection().items().orderedItems()); } }); angleSlider = new SpriterDemoAnimatorSlider(0, 360, 1f, skin, "%.0f") { @Override public void setValue(SpriterAnimator animator, float value) { spriterAnimator.setRotation(value); } @Override protected float getValue(SpriterAnimator animator) { return spriterAnimator.getRotation(); } }; pivotXSlider = new SpriterDemoAnimatorSlider(-1000f, 1000f, 1f, skin, "%.0f") { @Override public void setValue(SpriterAnimator animator, float value) { animator.setPivotX(value); } @Override protected float getValue(SpriterAnimator animator) { return animator.getPivotX(); } }; pivotYSlider = new SpriterDemoAnimatorSlider(-1000f, 1000f, 1f, skin, "%.0f") { @Override public void setValue(SpriterAnimator animator, float value) { animator.setPivotY(value); } @Override protected float getValue(SpriterAnimator animator) { return animator.getPivotY(); } }; scaleXSlider = new SpriterDemoAnimatorSlider(-10f, 10f, 0.1f, skin) { @Override public void setValue(SpriterAnimator animator, float value) { spriterAnimator.setScaleX(value); } @Override protected float getValue(SpriterAnimator animator) { return spriterAnimator.getScaleX(); } }; scaleYSlider = new SpriterDemoAnimatorSlider(-10f, 10f, 0.1f, skin) { @Override public void setValue(SpriterAnimator animator, float value) { spriterAnimator.setScaleY(value); } @Override protected float getValue(SpriterAnimator animator) { return spriterAnimator.getScaleY(); } }; alphaSlider = new SpriterDemoAnimatorSlider(0f, 1f, 0.01f, skin, "%.2f") { @Override public void setValue(SpriterAnimator animator, float value) { animator.setAlpha(value); } @Override protected float getValue(SpriterAnimator animator) { return animator.getAlpha(); } }; speedSlider = new SpriterDemoAnimatorSlider(0f, 10f, 0.1f, skin) { @Override public void setValue(SpriterAnimator animator, float value) { animator.setSpeed(value); } @Override protected float getValue(SpriterAnimator animator) { return animator.getSpeed(); } }; allAnimatorSliders = new SpriterDemoAnimatorSlider[] { scaleXSlider, scaleYSlider, pivotXSlider, pivotYSlider, angleSlider, alphaSlider, speedSlider }; metaLabel = new Label("Meta: ", skin); metaLabel.setWrap(true); metaLabel.setAlignment(Align.topLeft); spriterPlaceholder = new Label("No animator", skin); spriterPlaceholder.setAlignment(Align.center); spriterAnimator = new SpriterAnimatorActor(animator); spriterAnimator.debug(); playPauseButton = new ImageButton(skin, "play"); playPauseButton.setChecked(true); playPauseButton.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { boolean playing = playPauseButton.isChecked(); spriterAnimator.setDisabled(!playing); } }); timeSlider = new Slider(0f, 2000f, 1, false, skin); timeSlider.addListener(timeSliderListener = new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { if (animator == null) return; animator.setTime(timeSlider.getValue()); animator.update(0f); } }); timeLabel = new Label("---", skin); // Put everything in place Table titleTable = new Table(skin); titleTable.add(titleLabel).pad(6f); titleTable.add().expandX(); titleTable.add(fpsLabel).padRight(10f); Table selectionTable = new Table(skin); selectionTable.defaults().pad(3f); Table filesTable = new Table(skin); filesTable.row(); filesTable.add(fileChooser).expand().fillX(); filesTable.add(fileFinder).padLeft(2f).padRight(1f); Table animationsTable = new Table(skin); animationsTable.row(); animationsTable.add(animationChooser).expand().fill(); animationsTable.add(transitionCheckbox).fillX().padLeft(2f); ScrollPane scrollableCharmapChooser = new ScrollPane(charmapChooser); Table menuTable = new Table(skin); menuTable.defaults().pad(3f).expandX().fillX(); menuTable.row(); menuTable.add(titleTable).colspan(2); menuTable.row(); menuTable.add("File"); menuTable.add(filesTable).pad(4f); menuTable.row(); menuTable.add("Entity"); menuTable.add(entityChooser).pad(4f); menuTable.row(); menuTable.add("Animation"); menuTable.add(animationsTable).pad(4f); menuTable.row(); menuTable.add("Maps"); menuTable.add(scrollableCharmapChooser).pad(4f); menuTable.row(); menuTable.add("Angle"); menuTable.add(angleSlider); menuTable.row(); menuTable.add("Pivot X"); menuTable.add(pivotXSlider); menuTable.row(); menuTable.add("Pivot Y"); menuTable.add(pivotYSlider); menuTable.row(); menuTable.add("Scale X"); menuTable.add(scaleXSlider); menuTable.row(); menuTable.add("Scale Y"); menuTable.add(scaleYSlider); menuTable.row(); menuTable.add("Alpha"); menuTable.add(alphaSlider); menuTable.row(); menuTable.add("Speed"); menuTable.add(speedSlider); menuTable.row(); menuTable.add().expandY(); Table contentTable = new Table(skin); contentTable.row(); contentTable.add(metaLabel).left().expandX().maxHeight(1f); contentTable.row(); contentTable.stack(spriterPlaceholder, spriterAnimator).expand(); Table timelineTable = new Table(skin); timelineTable.row(); timelineTable.add("Timeline").expandX().align(Align.bottom); timelineTable.row(); timelineTable.add(timeSlider).expandX().fillX(); timelineTable.row(); timelineTable.add(timeLabel).expandX().align(Align.top); Table controlTable = new Table(skin); controlTable.add(playPauseButton).space(5f).expandY().fillY(); controlTable.add(timelineTable).expandX().fillX(); rootTable = new Table(skin); rootTable.setFillParent(true); rootTable.row(); rootTable.add(menuTable).expandY().fill(); rootTable.add(contentTable).expand().fill(); rootTable.row(); rootTable.add(controlTable).colspan(2).expandX().fillX(); stage.addActor(rootTable); // Bring input processing to the party InputProcessor globalInput = new InputProcessor() { @Override public boolean keyDown(int keycode) { switch (keycode) { case Keys.UP: case Keys.Z: case Keys.W: if (lastUsedSelectBox != null) lastUsedSelectBox.setSelectedIndex(Math.max(lastUsedSelectBox.getSelectedIndex() - 1, 0)); break; case Keys.DOWN: case Keys.S: if (lastUsedSelectBox != null) lastUsedSelectBox.setSelectedIndex(Math.min(lastUsedSelectBox.getSelectedIndex() + 1, lastUsedSelectBox.getItems().size - 1)); break; default: break; } return true; } @Override public boolean keyUp(int keycode) { return false; } @Override public boolean keyTyped(char character) { return false; } @Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { return false; } @Override public boolean touchUp(int screenX, int screenY, int pointer, int button) { return false; } @Override public boolean touchDragged(int screenX, int screenY, int pointer) { return false; } @Override public boolean mouseMoved(int screenX, int screenY) { return false; } @Override public boolean scrolled(int amount) { amount *= 0.05f; // Zoom coefficient scaleXSlider.setValue(scaleXSlider.getValue() + amount); scaleYSlider.setValue(scaleYSlider.getValue() + amount); return false; } }; Gdx.input.setInputProcessor(new InputMultiplexer(stage, globalInput)); // Add default test resources Array<String> testResources = new Array<String>(SpriterTestData.scml); testResources.addAll(SpriterTestData.scon); testResources.sort(); for (String path : testResources) addFile(Gdx.files.internal(path.replaceFirst("/", "")), assetManager); // Also go discover some unknown exotic resources! (won't work in jar though) Array<FileHandle> spriterFiles = SpriterDemoUtils.findFiles(new String[] { "scml", "scon" }); for (FileHandle f : spriterFiles) addFile(f, assetManager); fileChooser.setItems(files); lastUsedSelectBox = fileChooser; if (playPauseButton.isChecked()) animator.play(animator.getAnimations().iterator().next()); }