I would recommend representing the position of the animated sprite as a Vector2
, then to use the universal tween engine you would first have to implement a TweenAccessor
for that type;
public class Vector2Accessor implements TweenAccessor<Vector2> {
public static final int TYPE_XY = 1;
@Override
public int getValues(Vector2 target, int tweenType, float[] returnValues) {
switch (tweenType) {
case TYPE_XY:
returnValues[0] = target.x;
returnValues[1] = target.y;
return 2;
default:
assert false;
return -1;
}
}
@Override
public void setValues(Vector2 target, int tweenType, float[] newValues) {
switch (tweenType) {
case TYPE_XY:
target.x = newValues[0];
target.y = newValues[1];
break;
default:
assert false;
break;
}
}
}
After that it's a matter of registering the accessor, and updating the TweenManager
with the delta time before rendering the Animation
at the Vector2
position;
public class MyApplication extends ApplicationAdapter {
private TweenManager manager = new TweenManager();
private Vector2 position = new Vector2();
public MyApplication() {
Tween.registerAccessor(Vector2.class, new Vector2Accessor());
}
public void create() {
// Set the position to the left hand side of the screen, center vertically
position.set(0, Gdx.graphics.getHeight() / 2.0f);
Tween.to(position, Vector2Accessor.TYPE_XY, 5.0f).target(Gdx.graphics.getWidth(), Gdx.graphics.getHeight() / 2.0f).start(manager);
}
public void render() {
manager.update(Gdx.graphics.getDeltaTime());
// For brevity I'll just pretend batch and flyAnimation and elapsedTime exists here
batch.draw(flyAnimation2.getKeyFrame(elapsedTime, true), position.x,position.y, 0, 0, 124, 90, 1.0f, 1.0f, 90);
}
}