We are defining a 'MSContainer' named monkeyguy-anim-data. The 'monkey-guy' is the name of the texture to be used, and 8 is the number of rows and columns of the spritesheet
idle
We are defining an animation named 'idle'. It is made up of 1 frame starting at position 0
bend
We are defining an animation named 'bend'. It is made up of 8 frames starting at position 1
run
We are defining an animation named 'run'. It is made up of 8 frames starting at position 8
Write the code
Since MonkeySheet uses GoldMonkey, it has to be used like this. The path of the animation XML must be specified and passed to GoldMonkeyAppState, which must be loaded first in order to initialize the animation data.
!WARNING! Must use a separate AppState for managing the animations, because doing it inside the simpleInitApp won't allow GoldMonkeyAppState to initialize.
MSContainer
This class is a container of animations. After loading the XML, the animations are available by name.
MSControl
This is the control for animations, and keep track of the current position of the running animation for our sprite.
MSMaterialControl
This depends on MSControl and draw the sprite.
On TestAppState, your init will look like this:
you start the MonkeySheetAppState and set up the speed of anim_tick_duration (can use hard coded values if you prefer;
you create at least a MSContainer with the values of the XML;
you load at least an animation on the MSContainer;
you create a MSControl and attach it to a Geometry;
you create a MSMaterialControl with a reference to the MSControl
At this point you can run any animation by simply calling
MSControl.play(String animation);
Set the center of the sprite
Open the sprite with Gimp, reflect the image vertically and hover with the mouse on the center. Take note of the X and Y values and write on the JSON file
public class Main extends SimpleApplication {
public Main(AppState... appstates) {
super(appstates);
}
public static void main( String... args ) {
String gmPath[] = new String[]{
"assets/GoldMonkey/animations.xml"
};
Main main = new Main(new GoldMonkeyAppState(false, true, gmPath), new TestAppState());
main.start();
}
public void simpleInitApp() {
}
}