Reputation: 5024
When I have to move some sprite on my scene (for example, on 100px down), I'm using this code:
Timer timer = new Timer();
for (int i=0; i<10; i++) {
delay+=frameDelay;
timer.schedule(new TimerTask() {
@Override
public void run() {
sprite.setPosition(sprite.getX(), sprite.getY()+10);
}
},delay);
}
It works, but I wonder if there is much correct and/or more fast possibilities to do this.
Upvotes: 0
Views: 3727
Reputation: 2527
or look at the various Modifiers available - to move up/down, use a MoveYModifier - something like
yourSprite.registerEntityModifier(new MoveYModifier(time, startY, endY, new IEntityModifierListener() {
@Override
public void onModifierStarted(final IModifier<IEntity> pModifier, final IEntity pItem) {
yourActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
//Do anything here that you want to happen when the Modifier starts - like start a sound playing, etc
}
});
}
@Override
public void onModifierFinished(final IModifier<IEntity> pEntityModifier, final IEntity pEntity) {
yourActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
//Do anything here that you want to happen after the Modifier is through - like stop playing a sound, etc
}
}
});
}
}, EaseBounceOut.getInstance()));
The EaseBounceOut.getInstance() is just an example - it causes the Sprite to bounce at the end - there are lots of other EaseFunctions available.
Upvotes: 5