-
Notifications
You must be signed in to change notification settings - Fork 0
Spriter Integration
Let's suppose you have created some animations for a character in Spriter, and you want to use this animation in your game.
There are a pretty straight forward process to make this happen!
First, create a folder in the assets folder, that will contain your project (the images, and the .scml file)
The class responsible for creating a Spriter Animation GameObject is the SpriterAnimation
, so you can instance it on your player class, like this:
public class Personagem extends PlatformPlayer{
SpriterAnimation animation;
public Personagem(ObjectInfo info, MapProperties properties) {
super(info, properties);
animation = new SpriterAnimation(info, "spriter/proj.scml", new Vector2(get("x", Float.class) / State.PHYS_SCALE, get("y", Float.class) / State.PHYS_SCALE));
getState().putInScene(animation);
setJumpStrength(10);
setSpeed(5);
}
public boolean update(float delta) {
super.update(delta);
animation.getTransform().setPosition(
body.getWorldCenter().x,
body.getWorldCenter().y); //Here you can apply some offset if the sprite isnt fully aligned with the body
animation.setScale(new Vector2(1/4f, 1/4f)); //you can also scale up or down
animation.flip(direction == -1, false); //and flip in the x or y axis
}
This will render your animation with the default animation that is set on the Spriter Project
To change animations, you can simply call the method:
animation.setAnimation(animationName);
You can also make composed animations based on two animations. To do that you actually pass a Player object (not the one you created, the Player
class that already exists within Spriter library) that has the interpolation information. To create a player that is the interpolation of two animations, use the method:
animation.setPlayer(animation.createInterpolatedAnimation(String animationName1, String animationName2, float alpha));
and set the player with:
animation.setPlayer(Player anim);
You can do this if you want to, for example, interpolate between a Walk animation and an Idle animation, so the player can smoothly transition between the idle and Walk animation when walking:
That's it for Spriter Animations! If you want to learn how can you manage animations with an animation controller go to the Animation Controlling page!