List of usage examples for com.badlogic.gdx.scenes.scene2d Actor getX
public float getX()
From source file:broken.shotgun.throwthemoon.stages.GameStage.java
License:Open Source License
public GameStage(final AssetManager manager) { super(new StretchViewport(WIDTH, HEIGHT)); this.manager = manager; loadLevel();/*from w w w . j a v a 2 s. com*/ loadSounds(); loadFont(); random = new Random(System.currentTimeMillis()); fadingOut = false; background = new Background(manager); chain = new MoonChain(manager); player = new Player(manager); moon = new Moon(manager); moonImpactMeter = new MoonImpactMeter(moon); screenFadeActor = new Actor(); screenFadeActor.setBounds(0, 0, WIDTH, HEIGHT); screenFadeActor.setColor(Color.CLEAR); levelDebugRenderer = new LevelDebugRenderer(); screenLogger = new StringBuilder(); uiBatch = new SpriteBatch(); renderer = new ShapeRenderer(); renderer.setAutoShapeType(true); touchPoint = new Vector2(); resetLevel(); debug = isDebug(); setDebugAll(debug); Gdx.input.setInputProcessor(this); addListener(new ActorGestureListener() { @Override public void touchDown(InputEvent event, float x, float y, int pointer, int button) { if (pointer == 0 && !(event.getTarget() instanceof Enemy || event.getTarget() instanceof Boss || (boss != null && event.getTarget() instanceof MoonChain))) { player.moveTo(touchPoint.set(x, y)); } // FIXME replace String.format with StringBuilder for HTML if (isDebug()) Gdx.app.log("GameStage", String.format("touchDown %s %s", event.getType().toString(), event.getTarget().toString())); super.touchDown(event, x, y, pointer, button); } @Override public void touchUp(InputEvent event, float x, float y, int pointer, int button) { if (pointer == 0 && player.isWalking()) { player.stop(); } super.touchUp(event, x, y, pointer, button); } @Override public void pan(InputEvent event, float x, float y, float deltaX, float deltaY) { if (boss == null || (boss != null && !(event.getTarget() instanceof MoonChain))) { player.moveTo(touchPoint.set(x, y)); } super.pan(event, x, y, deltaX, deltaY); } @Override public void tap(InputEvent event, float x, float y, int count, int button) { player.performAttack(count); float deltaX = ((player.getX() + player.getOriginX()) - x); player.setFlipX(deltaX > 0); // FIXME replace String.format with StringBuilder for HTML if (isDebug()) { Actor target = event.getTarget(); Gdx.app.log("GameStage", String.format("tap type:%s target:%s [target x=%.2f y=%.2f] count:%d [x:%.2f, y:%.2f]", event.getType().toString(), target.toString(), target.getX(), target.getY(), count, x, y)); } super.tap(event, x, y, count, button); } @Override public void fling(InputEvent event, float velocityX, float velocityY, int button) { Gdx.app.log("GameStage", String.format("fling velocityX:%.2f velocityY:%.2f", velocityX, velocityY)); if (player.isMoonThrowEnabled() && velocityY < 0 && chain.isAttached() && event.getTarget() instanceof MoonChain) { int multiplier = (boss != null && boss.isDefeated()) ? 10 : 2; moon.addDistance(velocityY * multiplier); chain.animatePull(); } super.fling(event, velocityX, velocityY, button); } }); addListener(new InputListener() { int attackCounter = 0; @Override public boolean keyDown(InputEvent event, int keycode) { switch (keycode) { case Input.Keys.D: if (debug && player.isMoonThrowEnabled() && !moon.isFalling()) { moon.startFalling(); } break; case Input.Keys.K: if (debug) { clearAllEnemies(); } break; case Input.Keys.SPACE: attackCounter++; player.performAttack(attackCounter); return true; case Input.Keys.LEFT: player.velocity.x = -7; player.startWalkState(); return true; case Input.Keys.RIGHT: player.velocity.x = 7; player.startWalkState(); return true; case Input.Keys.UP: player.velocity.y = 7; player.startWalkState(); return true; case Input.Keys.DOWN: player.velocity.y = -7; player.startWalkState(); return true; } return super.keyDown(event, keycode); } @Override public boolean keyUp(InputEvent event, int keycode) { switch (keycode) { case Input.Keys.LEFT: case Input.Keys.RIGHT: player.velocity.x = 0; return true; case Input.Keys.UP: case Input.Keys.DOWN: player.velocity.y = 0; return true; } return super.keyUp(event, keycode); } }); }
From source file:broken.shotgun.throwthemoon.stages.GameStage.java
License:Open Source License
private void logPoisitions() { if (!debug)/*from w w w . j ava 2s .co m*/ return; vlog(String.format("Camera [x:%.0f, y:%.0f, width:%.0f, height:%.0f]", getCamera().position.x, getCamera().position.y, getCamera().viewportWidth, getCamera().viewportHeight)); vlog(String.format("Stage [width:%.0f, height:%.0f]", getWidth(), getHeight())); vlog(String.format("Screen [width:%d, height:%d]", getViewport().getScreenWidth(), getViewport().getScreenHeight())); vlog(String.format("FPS: %d", Gdx.graphics.getFramesPerSecond())); if (wallIndex < currentLevel.enemySpawnWallList.size()) vlog(String.format("Current spawn wall [index: %d, x: %d]", wallIndex, currentLevel.enemySpawnWallList.get(wallIndex).spawnWallX)); vlog(String.format("Moon [distance: %d]", moon.getDistance())); for (Actor entity : getActors()) { String tag = (entity instanceof Player) ? "Player" : (entity instanceof Enemy) ? "Enemy" : (entity instanceof Boss) ? "Boss" : null; if (tag != null) { vlog(String.format("%s [x:%.0f, y:%.0f]", tag, entity.getX(), entity.getY())); } } }
From source file:com.agateau.ui.menu.MenuItemGroup.java
License:Apache License
@Override public Rectangle getFocusRectangle() { MenuItem item = getCurrentItem(); Assert.check(item != null, "Cannot get focus rectangle of an invalid item"); Assert.check(item.isFocusable(), "Item " + item + " is not focusable"); mFocusRect.set(item.getFocusRectangle()); Actor actor = item.getActor(); mFocusRect.x += actor.getX(); mFocusRect.y += actor.getY();//from ww w .jav a 2s. c o m return mFocusRect; }
From source file:com.agateau.ui.menu.MenuItemGroup.java
License:Apache License
private MenuItem getItemAt(float x, float y) { for (MenuItem item : mItems) { if (!isItemVisible(item)) { continue; }/*from w w w . j a v a 2s . c o m*/ Actor actor = item.getActor(); // We do not use the item focus rect because it might only represent a part of the item // For example the focus rect of a GridMenuItem is the currently selected cell of the grid mActorRectangle.set(0, 0, actor.getWidth(), actor.getHeight()); for (; actor != mGroup && actor != null; actor = actor.getParent()) { mActorRectangle.x += actor.getX(); mActorRectangle.y += actor.getY(); } if (mActorRectangle.contains(x, y)) { return item; } } return null; }
From source file:com.ahsgaming.valleyofbones.screens.AbstractScreen.java
License:Apache License
public static Vector2 localToGlobal(Vector2 local, Actor actor) { Vector2 coords = new Vector2(local); Actor cur = actor; while (cur.getParent() != null) { coords.add(cur.getX(), cur.getY()); cur = cur.getParent();//ww w . j a v a2 s .c om } return coords; }
From source file:com.amerticum.chosenchess.controller.ControlleurEchiquer.java
License:Apache License
@Override public void tap(InputEvent event, float x, float y, int count, int button) { Actor target = event.getTarget(); // Tapped actor. int tx = (int) target.getX(); // Tapped tile x. int ty = (int) target.getY(); // Tapped tile y. if (target.getClass().getSuperclass().equals(Piece.class)) { Piece piece = (Piece) target;/*www .jav a 2s .c om*/ if ((((this.echiquier.tour % 2) == 0) && piece.estRouge) || (((this.echiquier.tour % 2) == 1) && !piece.estRouge)) { if (this.echiquier.selectedPiece == piece) { this.echiquier.selectedPiece = null; this.removeMoveHighlights(); } else { this.selectPiece(piece); } } else { this.movePiece(this.echiquier.selectedPiece, tx, ty); } } else { this.movePiece(this.echiquier.selectedPiece, tx, ty); } }
From source file:com.bagon.matchteam.mtx.scene2d.collision.CollisionDetector.java
License:Apache License
/** * Very precise point detection in an actor, think as virtual box in the * actual box with margin as precision amount * *//* w ww . ja va 2 s . co m*/ public static boolean isTouchPointCollide(float touchX, float touchY, Actor actor, float precisionAmount) { if (touchX > (actor.getX() + precisionAmount) && touchX < (actor.getX() + actor.getWidth() - precisionAmount) && touchY > (actor.getY() + precisionAmount) && touchY < (actor.getY() + actor.getHeight() - precisionAmount)) { logCollision2(actor); return true; } else { return false; } }
From source file:com.bagon.matchteam.mtx.utils.UtilsActor.java
License:Apache License
/** * Get the rectangle of an actor from its current position and size * *//*from www. ja v a 2s . c o m*/ public static Rectangle getRectangleOfActor(Actor actor) { return new Rectangle(actor.getX(), actor.getY(), actor.getWidth(), actor.getHeight()); }
From source file:com.bagon.matchteam.mtx.utils.UtilsPositioner.java
License:Apache License
/** * Set position of an actor due to another actor's position, , since actors * are complex objects, its variables pointing same reference with copies, * so the position will be set in original object * /*from w w w . j a va 2 s. c o m*/ * * @param actorToBePositioned * actor to be positioned * @param actorStable * actor to get position data * @param position * the position to set, comes from Position enum class * */ public static void setActorPoisiton(Actor actorToBePositioned, Actor actorStable, Position position) { float atp_W = actorToBePositioned.getWidth(); float atp_H = actorToBePositioned.getHeight(); float as_X = actorStable.getX(); float as_Y = actorStable.getY(); float as_XW = actorStable.getWidth() + as_X; float as_YH = actorStable.getHeight() + as_Y; setPosition(actorToBePositioned, atp_W, atp_H, as_X, as_Y, as_XW, as_YH, position); }
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//from w w w .ja va 2 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; } }