LibGDX 2D bitmap animation editor
Hello my fellow readers!
I am currently working on a super hidden project retro project that will use bitmap animations to avoid smooth movement(yes, really!)
Today I backed spine on kickstarter and hoping to use it later to bring some realism on my future games with smooth skeletal animations!
I was about a year ago working on a simple skeletal animation tool but It never got anywhere!
Today I implemented simple animation editor for 2D bitmap animations which are stored in simple XML format(no problem modders!)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<list> <AnimationSheetDefinition> <sheetName>hero</sheetName> <animationTexture>herosheet</animationTexture> <cols>8</cols> <rows>2</rows> <animations> <AnimationDefinition> <locations> <Location> <x>0</x> <y>0</y> </Location> </locations> <animationName>walk</animationName> </AnimationDefinition> <AnimationDefinition> <locations> <Location> <x>1</x> <y>1</y> </Location> </locations> <animationName>talk</animationName> </AnimationDefinition> </animations> </AnimationSheetDefinition> </list> |
I am also using XStream to handle the marshalling and unmarshalling of objects as I don’t realy like LibGDXs default XML library for a reason..
As you can see the structure is pretty straightforward!
- AnimationSheetDefinition
- sheetName
- animationTexture
- cols
- rows
- animations
-
AnimationDefinition
- locations
- x
- y
- animationName
- locations
and of course to avoid having to do all work by myself and to delegate it I created the GUI editor itself which this whole post was supposed to be about!
Its still quite messy but you get the idea by watching this little video I made!
Because there wasn’t “AnimationWidget” in LibGDX by default I had to create such but it was easy to implement and if anyone cares here it goes:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
package com.ruuhkis.widgets; import com.badlogic.gdx.graphics.g2d.Animation; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.scenes.scene2d.ui.Widget; public class AnimationWidget extends Widget { private Animation animation; private float time; public AnimationWidget(Animation animation) { this.animation = animation; } @Override public float getMinWidth() { TextureRegion region = animation.getKeyFrame(time); return region.getRegionWidth(); } @Override public float getMinHeight() { TextureRegion region = animation.getKeyFrame(time); return region.getRegionHeight(); } @Override public float getPrefWidth() { TextureRegion region = animation.getKeyFrame(time); return region.getRegionWidth(); } @Override public float getPrefHeight() { TextureRegion region = animation.getKeyFrame(time); return region.getRegionHeight(); } @Override public float getMaxWidth() { TextureRegion region = animation.getKeyFrame(time); return region.getRegionWidth(); } @Override public float getMaxHeight() { TextureRegion region = animation.getKeyFrame(time); return region.getRegionHeight(); } @Override public void draw(SpriteBatch batch, float parentAlpha) { super.draw(batch, parentAlpha); TextureRegion region = animation.getKeyFrame(time); batch.draw(region, getX(), getY(), getWidth(), getHeight()); } @Override public void act(float delta) { super.act(delta); time += delta; } } |
The source code is currently in private BitBucket repository so I can’t link it at the moment
