How to go through frames of an animation?

I finally got an animation working. It is a simple ninja man that walks jumps runs ect. I used the TestMilkJmeWrite to get it to work since it was a .ms3d object. It works great and I am stoked but it just runs through all of the animations one after another. I need to get it to only got through the jump phase (frames 0-29). How do I achieve this? I know this is a hard question to just answer so if there is a good tut on it I would appreciate the link/guidance. Thanks.

The Vector is a Collection.  You can use whatever Collection you want like LinkedList or Hashmap. 

So in the getKeyframeControllers method, we are adding the KeyframeController to our collection because we need to use them at a later time (to set the animation times).

Here is an example.

Node node = <getNodeFromImporter>;

Vector controllersV = new Vector();

// get keyframe controllers

// set times
setKeyFrameTimes(controllersV, 0f, 10f, KeyframeController.RT_WRP);

Does this make sense?

Its actually not that hard as long as you know when your animation times start and stop.

Here are the steps that you need to take

  1. Get the keyframe controllers (they should be imported and attached to your node object)
  2. Set the keyframe times for the node (you should do this in accordance with whatever animation action you want)

  3. getting the controllers

     * Gets all the keyframe controllers and adds them to the vector.
     * @param node gets the controllers from the node.
     * @param v the vector to add the controllers.
    private void getKeyframeControllers(Node node, Vector v){
        for(int i = 0; i < node.getChildren().size(); i++){
            v.add((KeyframeController) node.getChild(i).getController(0));

2. sets the controllers

     * Sets the animation time.
     * @param v contains the controllers to set.
     * @param timeIn the start time of the animation.
     * @param timeOut the stop time of the animation.
    private void setKeyFrameTimes(Vector v, float timeIn, float timeOut, int repeatType){
        for(int i = 0; i < v.size(); i++){

I hope that helps

Yes that helps a lot, that is exactly what I was looking for! One thing though what is the vector for that is getting passed into the getKeyFrameControllers method? Is it a directional vector or some sort? Thanks for your help.

Thanks for your help, and sorry it is taking me so long to get back but we were in the middle of finals week here at school. Ok now everything you said makes sense but eclipse is giving me this error.

java.lang.ClassCastException: com.jmex.model.animation.JointController cannot be cast to com.jmex.model.animation.KeyframeController

at gameFiles.Animation.setKeyFrameTimes(

at gameFiles.Animation.simpleInitGame(



at gameFiles.Animation.main(

It is happening at this line in the code – v.add((KeyframeController) node.getChild(i).getController(0));

So apparently you can't case KeyframeController like that. What is the problem here?

Thanks for your help again sorry I am a noob with JME

Try casting to a JointController?

    private void setKeyFrameTimes(Vector v, float timeIn, float timeOut, int repeatType){
        for(int i = 0; i < v.size(); i++){

Finally got it working. In case anyone wants to see the code here it is. Got it from somewhere else on the forums.

    public void playAnimation(Node n){

       JointController controller = (JointController) n.getController(0);
        int startFrame=0,  endFrame=14;
        controller.setRotation(2, 4.3f, 1, 1, 1);
       controller.setTimes(startFrame, endFrame);

And here is how I am loading the model

private Node createNinja(){
      try {
               new SimpleResourceLocator(Animation.class
      } catch (URISyntaxException e1) {
         logger.log(Level.WARNING, "unable to setup texture directory.", e1);

      MilkToJme converter = new MilkToJme();
      URL MSFile = Animation.class.getClassLoader().getResource(
      ByteArrayOutputStream BO = new ByteArrayOutputStream();

      try {
         converter.convert(MSFile.openStream(), BO);
      } catch (IOException e) {"IO problem writting the file!!!");;

      Node i = null;
      try {
         i = (Node) BinaryImporter.getInstance().load(
               new ByteArrayInputStream(BO.toByteArray()));
      } catch (IOException e) {"darn exceptions:" + e.getMessage());
      return i;