Search in sources :

Example 1 with SceneCamera

use of com.bladecoder.engine.model.SceneCamera in project bladecoder-adventure-engine by bladecoder.

the class CameraAction method run.

@Override
public boolean run(VerbRunner cb) {
    Vector2 pos2 = null;
    Float zoom2 = zoom;
    if (pos != null)
        pos2 = new Vector2(pos);
    float scale = EngineAssetManager.getInstance().getScale();
    SceneCamera camera = World.getInstance().getSceneCamera();
    if (zoom2 == null || zoom2 < 0)
        zoom2 = camera.getZoom();
    if (pos == null && target == null) {
        pos2 = new Vector2(camera.getPosition());
        pos2.x /= scale;
        pos2.y /= scale;
    }
    if (target != null) {
        BaseActor target = World.getInstance().getCurrentScene().getActor(this.target, false);
        float x = target.getX();
        float y = target.getY();
        if (target instanceof InteractiveActor) {
            Vector2 refPoint = ((InteractiveActor) target).getRefPoint();
            x += refPoint.x;
            y += refPoint.y;
        }
        if (pos2 != null) {
            pos2.x += x;
            pos2.y += y;
        } else {
            pos2 = new Vector2(x, y);
        }
    }
    if (followActor != null) {
        if (followActor.equals("none"))
            World.getInstance().getCurrentScene().setCameraFollowActor(null);
        else {
            World.getInstance().getCurrentScene().setCameraFollowActor((SpriteActor) World.getInstance().getCurrentScene().getActor(followActor, false));
        }
    }
    if (duration == null || duration == 0) {
        camera.setZoom(zoom2);
        camera.setPosition(pos2.x * scale, pos2.y * scale);
        return false;
    } else {
        camera.startAnimation(pos2.x * scale, pos2.y * scale, zoom2, duration, interpolation, wait ? cb : null);
    }
    return wait;
}
Also used : SceneCamera(com.bladecoder.engine.model.SceneCamera) Vector2(com.badlogic.gdx.math.Vector2) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) BaseActor(com.bladecoder.engine.model.BaseActor)

Aggregations

Vector2 (com.badlogic.gdx.math.Vector2)1 BaseActor (com.bladecoder.engine.model.BaseActor)1 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)1 SceneCamera (com.bladecoder.engine.model.SceneCamera)1