Search in sources :

Example 1 with SpritePosTween

use of com.bladecoder.engine.anim.SpritePosTween in project bladecoder-adventure-engine by bladecoder.

the class PositionAnimAction method run.

@Override
public boolean run(VerbRunner cb) {
    float scale = EngineAssetManager.getInstance().getScale();
    BaseActor a = World.getInstance().getCurrentScene().getActor(actor, true);
    float x = a.getX();
    float y = a.getY();
    if (target != null) {
        BaseActor target = World.getInstance().getCurrentScene().getActor(this.target, false);
        x = target.getX();
        y = target.getY();
        if (target instanceof InteractiveActor) {
            Vector2 refPoint = ((InteractiveActor) target).getRefPoint();
            x += refPoint.x;
            y += refPoint.y;
        }
        if (pos != null) {
            x += pos.x * scale;
            y += pos.y * scale;
        }
    } else if (pos != null) {
        x = pos.x * scale;
        y = pos.y * scale;
    }
    if (speed == 0 || !(a instanceof SpriteActor)) {
        a.setPosition(x, y);
        return false;
    } else {
        // WARNING: only spriteactors support animation
        float s;
        if (mode != null && mode == Mode.SPEED) {
            Vector2 p0 = new Vector2(a.getX(), a.getY());
            s = p0.dst(x, y) / (scale * speed);
        } else {
            s = speed;
        }
        SpritePosTween t = new SpritePosTween();
        t.start((SpriteActor) a, repeat, count, x, y, s, interpolation, wait ? cb : null);
        ((SpriteActor) a).addTween(t);
    }
    return wait;
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) BaseActor(com.bladecoder.engine.model.BaseActor) SpriteActor(com.bladecoder.engine.model.SpriteActor) SpritePosTween(com.bladecoder.engine.anim.SpritePosTween)

Aggregations

Vector2 (com.badlogic.gdx.math.Vector2)1 SpritePosTween (com.bladecoder.engine.anim.SpritePosTween)1 BaseActor (com.bladecoder.engine.model.BaseActor)1 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)1 SpriteActor (com.bladecoder.engine.model.SpriteActor)1