-
Notifications
You must be signed in to change notification settings - Fork 1
Animations
☕️ Miguel edited this page Dec 1, 2016
·
14 revisions
Animations are already supported by libgdx natively. However, this implementation is too generic to fit into the braingdx framework. Instead, braingdx implements its own Animation Utility which is easy to use. Imagine the following spritesheet:
As you can see the sprite sheet contains 8 different characters in total, each of them has 4 different animations for each direction. This is how you can animate the second character from the top left in braingdx:
/* in your AbstractScreen implementation */
// get the tileset as a texture, alternatively load it directly with libgdx
// The ID of your character
final int RPG_CHARACTER_ID = 1;
Texture texture = SharedAssetManager.getInstance().get(Assets.RPG.CHARACTER_TILESET);
// Convert the texture into a sprite sheet and describe how many tiles exist
SpriteSheet sheet = new SpriteSheet(texture, 12, 8);
// Describe how GameObjects of type 'RPG_CHARACTER_ID' should be rendered
getRenderManager().register(RPG_CHARACTER_ID, new AnimationRenderer(
new SpriteSheetAnimation(sheet)
// 4th tile from the left (3=index)
.origin(3, 0)
// change frame every 200ms
.interval(0.2f)
// Animate directional
.direction(Direction.HORIZONTAL)
// Animate to the end and then backwards and repeat
.type(AnimationTypes.FORWARD_YOYO)
// the animation of the character has only 3 frames in total
.frames(3)
)
);
The result will be a moving character which walks down without moving.