use of com.bladecoder.engine.ui.SceneScreen in project bladecoder-adventure-engine by bladecoder.
the class ScreenPositionAction method run.
@Override
public boolean run(VerbRunner cb) {
Scene s = actor.getScene();
BaseActor a = s.getActor(actor.getActorId(), true);
if (position != null) {
float scale = EngineAssetManager.getInstance().getScale();
Viewport viewport = ((SceneScreen) BladeEngine.getAppUI().getScreen(Screens.SCENE_SCREEN)).getViewport();
Vector3 v = new Vector3(position.x * scale, position.y * scale, 0);
if (anchor == Anchor.CENTER) {
v.x += viewport.getWorldWidth() / 2;
v.y += viewport.getWorldHeight() / 2;
} else if (anchor == Anchor.TOP_LEFT) {
v.x += 0;
v.y += viewport.getWorldHeight();
} else if (anchor == Anchor.TOP_RIGHT) {
v.x += viewport.getWorldWidth();
v.y += viewport.getWorldHeight();
} else if (anchor == Anchor.BOTTOM_RIGHT) {
v.x += viewport.getWorldWidth();
v.y += 0;
} else if (anchor == Anchor.BOTTOM_LEFT) {
v.x += 0;
v.y += 0;
} else if (anchor == Anchor.TOP) {
v.x += viewport.getWorldWidth() / 2;
v.y += viewport.getWorldHeight();
} else if (anchor == Anchor.BOTTOM) {
v.x += viewport.getWorldWidth() / 2;
v.y += 0;
} else if (anchor == Anchor.LEFT) {
v.x += 0;
v.y += viewport.getWorldHeight() / 2;
} else if (anchor == Anchor.RIGHT) {
v.x += viewport.getWorldWidth();
v.y += viewport.getWorldHeight() / 2;
}
// viewport.project(v);
v.x *= viewport.getScreenWidth() / viewport.getWorldWidth();
v.y *= viewport.getScreenHeight() / viewport.getWorldHeight();
// v.y = viewport.getScreenHeight() - v.y;
v.y = Gdx.graphics.getHeight() - v.y;
World.getInstance().getCurrentScene().getCamera().unproject(v, 0, 0, viewport.getScreenWidth(), viewport.getScreenHeight());
a.setPosition(v.x, v.y);
}
return false;
}
Aggregations