@Override public void create () { // create a stage and a camera controller so we can pan the view. stage = new Stage();; camController = new OrthoCamController((OrthographicCamera)stage.getCamera()); // we know it's an ortho cam at this point! Gdx.input.setInputProcessor(camController); // load a dummy texture texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg")); // populate the stage with some actors and groups. for (int i = 0; i < 5000; i++) { Actor img = new CullableActor("img" + i, texture, (OrthographicCamera)stage.getCamera()); img.setX((float)Math.random() * 480 * 10); img.setY((float)Math.random() * 320 * 10); stage.addActor(img); } // we also want to output the number of visible actors, so we need a SpriteBatch and a BitmapFont batch = new SpriteBatch(); font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false); }
public TypedGdxQuery<T> x(float x){ t.setX((int)x); return this; }
public UI<T> setX(float x) { t.setX(x); return this; }
public GdxQuery x(float x){ for(Actor actor:list()) actor.setX((int)x); return this; }
private void setActorPos (Actor actor, float pos) { if (isVertical) { actor.setY(pos); } else { actor.setX(pos); } }
public UI<T> setX(Actor actor) { t.setX(actor.getX()); return this; }
/**aligin the Actor to the center of the screen */ public static void centerActor(final Actor actor){ actor.setX( ( Engine.getWidth() - actor.getWidth() )/2 ); actor.setY( ( Engine.getHeight() - actor.getHeight() )/2 ); } }
public TypedGdxQuery<T> center(boolean setPosition) { t.setOrigin(Align.center); if(t instanceof Image) ((Image)t).setAlign(Align.center); if(t instanceof Label) ((Label) t).setAlignment(Align.center); if(setPosition) { t.setX(t.getX() - t.getWidth() / 2); t.setY(t.getY() - t.getHeight() / 2); } return this; }
public GdxQuery center(boolean setPosition) { for(Actor actor : list()){ actor.setOrigin(Align.center); if(actor instanceof Image) ((Image)actor).setAlign(Align.center); if(actor instanceof Label) ((Label) actor).setAlignment(Align.center); if(setPosition){ actor.setX(actor.getX() - actor.getWidth() / 2); actor.setY(actor.getY() - actor.getHeight() / 2); } } return this; }
child.setWidth(Math.abs(getAnchoredX(toLeft) - (getAnchoredX(toRight) + getScaledWidth(toRight)))); } else if (toLeft != null) { child.setX(getAnchoredX(toLeft) - getScaledWidth(child)); child.setX(getAnchoredX(toRight) + getScaledWidth(toRight)); if (alignInParent == Align.bottomLeft) return; if ((alignInParent & Align.center) == Align.center) { child.setX((parentW - getScaledWidth(child)) * 0.5f); child.setY((parentH - getScaledHeight(child)) * 0.5f); child.setX(0); if (toLeft != null) { child.setWidth(getAnchoredX(toLeft)); child.setWidth(parentW - (getAnchoredX(toRight) + getScaledWidth(toRight))); child.setX(parentW - getScaledWidth(child));
/** * Makes sures that actor will be fully visible in stage. If it's necessary actor position will be changed to fit it * on screen. */ public static void keepWithinStage (Stage stage, Actor actor) { //taken from scene2d.ui Window Camera camera = stage.getCamera(); if (camera instanceof OrthographicCamera) { OrthographicCamera orthographicCamera = (OrthographicCamera) camera; float parentWidth = stage.getWidth(); float parentHeight = stage.getHeight(); if (actor.getX(Align.right) - camera.position.x > parentWidth / 2 / orthographicCamera.zoom) actor.setPosition(camera.position.x + parentWidth / 2 / orthographicCamera.zoom, actor.getY(Align.right), Align.right); if (actor.getX(Align.left) - camera.position.x < -parentWidth / 2 / orthographicCamera.zoom) actor.setPosition(camera.position.x - parentWidth / 2 / orthographicCamera.zoom, actor.getY(Align.left), Align.left); if (actor.getY(Align.top) - camera.position.y > parentHeight / 2 / orthographicCamera.zoom) actor.setPosition(actor.getX(Align.top), camera.position.y + parentHeight / 2 / orthographicCamera.zoom, Align.top); if (actor.getY(Align.bottom) - camera.position.y < -parentHeight / 2 / orthographicCamera.zoom) actor.setPosition(actor.getX(Align.bottom), camera.position.y - parentHeight / 2 / orthographicCamera.zoom, Align.bottom); } else if (actor.getParent() == stage.getRoot()) { float parentWidth = stage.getWidth(); float parentHeight = stage.getHeight(); if (actor.getX() < 0) actor.setX(0); if (actor.getRight() > parentWidth) actor.setX(parentWidth - actor.getWidth()); if (actor.getY() < 0) actor.setY(0); if (actor.getTop() > parentHeight) actor.setY(parentHeight - actor.getHeight()); } } }
actorToBePositioned.setX((as_XW / 2.0f) - atp_W / 2.0f); actorToBePositioned.setY((as_YH / 2.0f) - atp_H / 2.0f); break;