Skip to content
tespirit edited this page Feb 9, 2011 · 2 revisions

Skeletal animations are all controlled by using a Player object. The Player object allows you to link an animation to the root skeleton joint. This can be setup in the Bamporter, if you are saving out the player. If you are saving out the player, loading the player is a simple line of code:

BambooAsset asset = Assets.loadBamboo("some_file.bam");
...
view.addBamboo(asset);

//After the asset is loaded, you can get the players for this. In this example, we are
//assuming that there is only 1 player in this file. Typically this is the case.
Player player = asset.getPlayers().get(0);
...
//The player now allows us to play an animation and select a clip to play.
//To play the first clip, just call play.
player.play();
...
//Now we can make it so that a different clip will now play.
player.setActiveClip("run");
...
//And some other things the player can do:
player.playReverse();
...
player.pause();
...
player.restart(); //returns the player time to 0

Ideally you want to have all your animations set as clips so that only 1 player is needed per skeleton. The Bamporter has a function for merging animations as clips if your artists prefer to keep each animation as a separate file.

To create a player by code, do the following:

BambooAsset asset = Assets.loadBamboo("some_file.bam");
...
for(Node node : asset.getScenes()){
  view.addSceneNode(node);
}

Player player = new Player();

//set the skeleton by joint name
player.setSkeleton("Mr. Skeleton");
player.setAnimation("some animation that was in an asset file that was loaded");
view.getRenderer().addUpdater(player);
...

And that is pretty much it! You can have the player controlled in an event listener so that it can change depending on the input.

For more advanced animation control, you will need to use an animation state machine. When a state machine is built for bamboo, I'll add notes on how to use it. Till then, you should be able to get some standard animations playing, such as running or standing still or attacking, etc.