Tweens - Gornova/MarteEngine GitHub Wiki
If you have completed Animate sprite tutorial it's time to take a look to Tweens.
Tweens
As game developer one of the most common thing is moving stuff around. Usually you can do it changing coordinates of an Entity, but sometimes you have different needs. Image to change player speed following a rule, for example quadratic rule. MarteEngine provide developer with few class (and ability to extend this mechanisms) to change position of an Entity: all integrated into Entity itself.
An Example To run this example, just create a World and add this EntityWithTween:
public class EntityWithTween extends Entity {
private Tweener tweener;
public EntityWithTween(float x, float y) {
super(x, y);
setGraphic(ResourceManager.getImage("image"));
// add to this entity a tweener
tweener = new Tweener();
// add a new Tween to tweener
tweener.add(new Tween(new LinearMotion(x, y, 400,
400, 100, Ease.BOUNCE_IN), true));
// start tweens into tweener
tweener.start();
}
@Override
public void update(GameContainer container, int delta)
throws SlickException {
super.update(container, delta);
// update player position according to tween
setPosition(tweener.apply(this));
}
}
All this code now seems to be a little familiar, right? What is new are: 1) Tweener class: don't panic! It's just a container for all your tweens. Yes, you can choose to add different tweens to your Entity and then Tweener handle all of them, in sequence! 2) Tween: in this example we declare a basic type of with linear motion from current position of entity (x,y) to (400,400) using an ease function, in this case, BOUNCE_IN. Easing function provide calculation to simulate a bouncing entity
Try code by yourself! It's easy and fun!
MarteEngine version 0.3