List of usage examples for com.badlogic.gdx.scenes.scene2d Actor setPosition
public void setPosition(float x, float y)
From source file:ateamproject.kezuino.com.github.render.screens.GameScreen.java
@Override public void render(float delta) { // Render Game and UI. super.render(delta); switch (getSession().getState()) { case GameOverHighscoreReached: PacketKick packet = new PacketKick(PacketKick.KickReasonType.GAME, null, null); Client.getInstance().send(packet); game.setScreen(new HighscoreScreen(game, true)); break;/*from w w w . ja va2 s. com*/ case GameOver: //getSession().end(); game.setScreen(new GameOverScreen(game, getSession().getScore())); break; case Completed: Actor btnContinue = new TextButton("Doorgaan", skin); Actor lblEndGameText = new Label("Je score is:", skin); Actor lblScore = new Label(Integer.toString(getSession().getScore().valueOf()), skin); btnContinue.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { btnContinue.remove(); lblEndGameText.remove(); lblScore.remove(); start(getSession().getScore()); Client.getInstance().send(new PacketLaunchGame(false, BaseScreen.getSession().getLevel() + 1, BaseScreen.getSession().getScore().valueOf(), Client.getInstance().getId())); } }); lblEndGameText.setPosition(stage.getWidth() / 2 - lblEndGameText.getWidth() / 2, stage.getHeight() - 80); lblScore.setPosition(stage.getWidth() / 2 - lblScore.getWidth() / 2, stage.getHeight() - 100); btnContinue.setSize(200, 40); btnContinue.setPosition(stage.getWidth() / 2 - btnContinue.getWidth() / 2, stage.getHeight() / 4 - btnContinue.getHeight() / 2); if (Client.getInstance().isHost()) { stage.addActor(btnContinue); } stage.addActor(lblEndGameText); stage.addActor(lblScore); getSession().end(); break; } }
From source file:com.agateau.ui.menu.Menu.java
License:Apache License
private void updateGroupBounds() { Actor actor = mGroup.getActor(); actor.setWidth(getWidth() - 2 * mStyle.focusPadding); ((Layout) actor).invalidate();//from ww w. jav a 2 s. c om ((Layout) actor).validate(); actor.setPosition(mStyle.focusPadding, mStyle.focusPadding); }
From source file:com.agateau.ui.menu.Menu.java
License:Apache License
void onGroupBoundariesChanged() { Actor actor = mGroup.getActor(); actor.setPosition(mStyle.focusPadding, mStyle.focusPadding); setSize(getWidth(), actor.getHeight() + 2 * mStyle.focusPadding); invalidateHierarchy();/* w w w . j av a 2s . c om*/ }
From source file:com.agateau.ui.menu.MenuItemGroup.java
License:Apache License
private void layoutItems() { // Keep in sync with computeHeight()! float y = 0;// w w w . ja v a 2 s. c o m Menu.MenuStyle style = mMenu.getMenuStyle(); final float spacing = style.focusPadding * 2 + style.spacing; for (int idx = mItems.size - 1; idx >= 0; --idx) { MenuItem item = mItems.get(idx); ItemInfo info = mInfoForItem.get(item); if (!info.visible) { continue; } Actor actor = item.getActor(); if (actor instanceof Layout) { ((Layout) actor).invalidate(); ((Layout) actor).validate(); } float x = 0; float width = mGroup.getWidth(); if (info.label != null) { info.label.setPosition(0, y); x = mMenu.getLabelColumnWidth(); width -= x; } float ratio = mItemForActor.get(actor).getParentWidthRatio(); if (ratio > 0) { actor.setWidth(width * ratio); } if (info.label == null) { x += (width - actor.getWidth()) / 2; } actor.setPosition(x, y); y += actor.getHeight() + spacing; } }
From source file:com.bagon.matchteam.mtx.utils.UtilsPositioner.java
License:Apache License
/** Advanced positioner */ private static void setPosition(Actor actorToBePositioned, float atp_W, float atp_H, float as_X, float as_Y, float as_XW, float as_YH, Position position) { // FIXME//w ww. j av a2 s . c o m // No 0.0 should be used, use as_xw and others // Test all position later IMPORTANT !!! switch (position) { case CENTER: actorToBePositioned.setX((as_XW / 2.0f) - atp_W / 2.0f); actorToBePositioned.setY((as_YH / 2.0f) - atp_H / 2.0f); break; case SAME: actorToBePositioned.setPosition(as_X, as_Y); break; case LEFT: actorToBePositioned.setPosition(as_X, as_YH / 2.0f - atp_H / 2.0f); break; case TOP_LEFT: actorToBePositioned.setPosition(as_X, as_YH - atp_H); break; case TOP_LEFT_CENTER: actorToBePositioned.setPosition(as_X - atp_W / 2.0f, as_YH - atp_H / 2.0f); break; case TOP_RIGHT: actorToBePositioned.setPosition(as_XW - atp_W, as_YH - atp_H); break; case TOP_RIGHT_CENTER: actorToBePositioned.setPosition(as_XW - atp_W / 2.0f, as_YH - atp_H / 2.0f); break; case TOP_CENTER: actorToBePositioned.setPosition(as_XW / 2.0f - atp_W / 2.0f, as_YH - atp_H); break; case BOTTOM_LEFT: actorToBePositioned.setPosition(as_X, as_Y); break; case BOTTOM_LEFT_CENTER: actorToBePositioned.setPosition(as_X - atp_W / 2.0f, as_Y - atp_H / 2.0f); break; case BOTTOM_RIGHT: actorToBePositioned.setPosition(as_XW - atp_W, as_Y); break; case BOTTOM_RIGHT_CENTER: actorToBePositioned.setPosition(as_XW - atp_W / 2.0f, as_Y - atp_H / 2.0f); break; case BOTTOM_CENTER: actorToBePositioned.setPosition(as_XW / 2.0f - atp_W / 2.0f, as_Y); break; case RIGHT_CENTER: actorToBePositioned.setPosition(as_XW - atp_W, as_YH / 2.0f - atp_H / 2.0f); break; default: actorToBePositioned.setPosition(actorToBePositioned.getX(), actorToBePositioned.getY()); break; } }
From source file:com.bladecoder.engine.ui.PieMenu.java
License:Apache License
public void show(InteractiveActor a, float x, float y) { setVisible(true);//from w w w . j a v a2s . co m this.x = x; this.y = y; iActor = a; // DRAW TARGET DESCRIPTION desc = iActor.getDesc(); if (desc != null) { if (desc.charAt(0) == I18N.PREFIX) desc = I18N.getString(desc.substring(1)); layout.setText(font, desc); } Actor rightButton; if (a.getVerb("talkto") != null) { talktoButton.setVisible(true); pickupButton.setVisible(false); rightButton = talktoButton; } else { talktoButton.setVisible(false); pickupButton.setVisible(true); rightButton = pickupButton; } float margin = DPIUtils.getMarginSize(); // FITS TO SCREEN if (x < lookatButton.getWidth() + margin) this.x = lookatButton.getWidth() + margin; else if (x > viewportWidth - lookatButton.getWidth() - margin) this.x = viewportWidth - lookatButton.getWidth() - margin; if (y < margin) this.y = margin; else if (y > viewportHeight - lookatButton.getHeight() - margin) this.y = viewportHeight - lookatButton.getHeight() - margin; //lookatButton.setPosition(this.x - lookatButton.getWidth() - margin / 2, this.y + margin); lookatButton.setPosition(this.x - lookatButton.getWidth() / 2, this.y - lookatButton.getHeight() / 2); lookatButton.addAction(Actions.moveTo(this.x - lookatButton.getWidth() - margin / 2, this.y + margin, .1f)); // rightButton.setPosition(this.x + margin / 2, this.y + margin); rightButton.setPosition(this.x - lookatButton.getWidth() / 2, this.y - lookatButton.getHeight() / 2); rightButton.addAction(Actions.moveTo(this.x + margin / 2, this.y + margin, .1f)); }
From source file:com.blastedstudios.gdxworld.util.ui.Scene2DUtils.java
License:Apache License
/** Adds the given Actor to the given Group at the coordinates relative to the Stage. * @param actor the Actor to add to the given Group * @param newParent the Group to add the given Actor to */ public static void addAtStageCoordinates(Actor actor, Group newParent) { tmp.set(positionInStageCoordinates(actor)); newParent.stageToLocalCoordinates(tmp); newParent.addActor(actor);/*from w w w . jav a2 s .c o m*/ actor.setPosition(tmp.x, tmp.y); }
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. j a v a 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.kotcrab.vis.editor.util.scene2d.VisDragAndDrop.java
License:Apache License
public void addSource(final Source source) { DragListener listener = new DragListener() { public void dragStart(InputEvent event, float x, float y, int pointer) { if (activePointer != -1) { event.stop();/*www . j a va 2 s . c om*/ return; } activePointer = pointer; dragStartTime = System.currentTimeMillis(); payload = source.dragStart(event, getTouchDownX(), getTouchDownY(), pointer); event.stop(); if (cancelTouchFocus && payload != null) source.getActor().getStage().cancelTouchFocusExcept(this, source.getActor()); } public void drag(InputEvent event, float x, float y, int pointer) { if (payload == null) return; if (pointer != activePointer) return; Stage stage = event.getStage(); Touchable dragActorTouchable = null; if (dragActor != null) { dragActorTouchable = dragActor.getTouchable(); dragActor.setTouchable(Touchable.disabled); } // Find target. Target newTarget = null; isValidTarget = false; float stageX = event.getStageX() + touchOffsetX, stageY = event.getStageY() + touchOffsetY; Actor hit = event.getStage().hit(stageX, stageY, true); // Prefer touchable actors. if (hit == null) hit = event.getStage().hit(stageX, stageY, false); if (hit != null) { for (int i = 0, n = targets.size; i < n; i++) { Target target = targets.get(i); if (!target.getActor().isAscendantOf(hit)) continue; newTarget = target; target.getActor().stageToLocalCoordinates(tmpVector.set(stageX, stageY)); break; } } //if over a new target, notify the former target that it's being left behind. if (newTarget != target) { if (target != null) target.reset(source, payload); target = newTarget; } //with any reset out of the way, notify new targets of drag. if (newTarget != null) { isValidTarget = newTarget.drag(source, payload, tmpVector.x, tmpVector.y, pointer); } if (dragActor != null) dragActor.setTouchable(dragActorTouchable); // Add/remove and position the drag actor. Actor actor = null; if (target != null) actor = isValidTarget ? payload.getValidDragActor() : payload.getInvalidDragActor(); if (actor == null) actor = payload.getDragActor(); if (actor == null) return; if (dragActor != actor) { if (dragActor != null) dragActor.remove(); dragActor = actor; stage.addActor(actor); } float actorX = event.getStageX() + dragActorX; float actorY = event.getStageY() + dragActorY - actor.getHeight(); if (keepWithinStage) { if (actorX < 0) actorX = 0; if (actorY < 0) actorY = 0; if (actorX + actor.getWidth() > stage.getWidth()) actorX = stage.getWidth() - actor.getWidth(); if (actorY + actor.getHeight() > stage.getHeight()) actorY = stage.getHeight() - actor.getHeight(); } actor.setPosition(actorX, actorY); if (currentSceneCamera != null && editingSettings.isSnapEnabledOrKeyPressed()) { float gridSize = gridSettings.config.gridSize; actor.setPosition(MathUtils.floor(currentSceneCamera.getInputX() / gridSize) * gridSize, MathUtils.floor(currentSceneCamera.getInputY() / gridSize) * gridSize); Vector3 v = currentSceneCamera.project(tmpVector3.set(actor.getX(), actor.getY(), 0)); actor.setPosition(v.x, v.y); } } public void dragStop(InputEvent event, float x, float y, int pointer) { if (pointer != activePointer) return; activePointer = -1; if (payload == null) return; if (System.currentTimeMillis() - dragStartTime < dragTime) isValidTarget = false; if (dragActor != null) dragActor.remove(); if (isValidTarget) { float stageX = event.getStageX() + touchOffsetX, stageY = event.getStageY() + touchOffsetY; target.getActor().stageToLocalCoordinates(tmpVector.set(stageX, stageY)); target.drop(source, payload, tmpVector.x, tmpVector.y, pointer); } source.dragStop(event, x, y, pointer, payload, isValidTarget ? target : null); if (target != null) target.reset(source, payload); payload = null; target = null; isValidTarget = false; dragActor = null; } }; listener.setTapSquareSize(tapSquareSize); listener.setButton(button); source.getActor().addCaptureListener(listener); sourceListeners.put(source, listener); }
From source file:com.quadbits.gdxhelper.controllers.LinearTrajectoryController.java
License:Apache License
@Override public void control(Actor actor, float deltaSeconds) { float deltaMillis = deltaSeconds * 1000; // out of scene? if (outOfScene) { // increase time currentOutOfSceneTimeMillis += deltaMillis; // check if we should make the actor enter the scene again if (currentOutOfSceneTimeMillis >= outOfSceneTimeMillis) { enterScene(actor);/*from w ww. j a v a 2 s . c o m*/ } // otherwise, keep on waiting else { return; } } // advance interpolation currentInterpolationValue += interpolationStep * deltaMillis; if (currentInterpolationValue > 1) { currentInterpolationValue = 1; } // check if we have arrived to target if (currentInterpolationValue == 1) { exitScene(actor); return; } // move actor tmpVector.set(currentSource); tmpVector.lerp(currentTarget, currentInterpolationValue); actor.setPosition(tmpVector.x, tmpVector.y); }