Controlling the animation

I'm having a problems controlling the keyframes of one animation of my game…



When the player hits the key "A", the character must punch it's enemy, the problem is that: if the player hits the key too quickly, the full animation of the punch is not displayed. The whole animation is viwed only when the player keeps pressing the key "A" and do not releases it until the last keyframe…



I'm sending the code related to that part of the game and some images to make it easier for you guys to understand.


ifbattle== false){
   if (keyboard.isValidCommand("a")){
      Principal.setKeyFrames(2.7f, 3.29f, 20, Controller.RT_CLAMP);
      battle = keyboard.getKeyInput().isKeyDown(KeyInput.KEY_A );
   }
}
      
else i f( battle == true ) {
   if ( keyboard.getKeyInput().isKeyDown( KeyInput.KEY_A ) == false ){
      Principal.setKeyFrames(1.8f, 2.39f, 1, Controller.RT_CYCLE);
      battle = keyboard.getKeyInput().isKeyDown(KeyInput.KEY_A );
   }
}



public static void setKeyFrames(float tempoInicial, float tempoFinal, float velocidade, int repetir){
      kc.setSpeed(velocidade);
      kc.setRepeatType(repetir);
      kc.setNewAnimationTimes(tempoInicial, tempoFinal);
   }



("A" keep pressed )



("A" pressed and released quickly)


Thanks!

You are going to have to monitor this yourself. The KeyframeController is just doing what you are telling it to do (setting the animation times). So, what I would do is enhance your ifBattle test a little bit more, before switching it back to false, make sure the animation time is appropriate for the finished animation.

looking good, btw :slight_smile:

What hell is btw?

XD

(By the way)

Thx guys…I still have no idea how to control the Keyframe time…I will try a little harder how to do that…



Thx XD

Yikes, there is not getter for the current time…



adding getCurrentTime and getCurrentFrame to cvs. Sorry about that. It's in CVS now.

The idea that has crossed my mind right now is to add a variable inside the update method that will receive the keyframe value of the moment the player presses "A", and will be increased on every step, until the variable's value is equal to the animation's final keyframe value…



Any comments?



Thx guys!


if(battle == false){
   if (keyboard.isValidCommand("a")){
      Particulas.getParticulas();
      Principal.setKeyFrames(2.7f, 3.29f, 20, Controller.RT_CLAMP);
   }
   keyControlerTime = keyControlerTime + 0.01f;
   if(keyControlerTime > 3.29f){
                   battle = true;
      keyControlerTime = 2.7f;
   }      
      }
      if(battle == true){
   Principal.setKeyFrames(1.8f, 2.39f, 1, Controller.RT_CYCLE);
   battle = !battle;
}



Now its working...

Better…


public void update(float tempo){
      if (tempoVerificador == true){
         this.tempo = this.tempo + 0.02f;
         verificaTempoKeyFrame();
      }
      if(golpe == false){
         if (keyboard.isValidCommand("a")){
            socoFraco();
            setKeyFrameFim(2.4f);
            this.tempo = 1.8f;
            tempoVerificador = true;
            golpe = true;
            if(particulas == false){
               Particulas.createParticulas();
               particulas = !particulas;
            }
            return;
         }
         if (keyboard.isValidCommand("s")){
            socoMedio();                              
            setKeyFrameFim(3.3f);
            this.tempo = 2.7f;
            tempoVerificador = true;
            golpe = true;
            if(particulas == false){
               Particulas.createParticulas();
               particulas = !particulas;
            }
            return;
         }
         if (keyboard.isValidCommand("d")){
            socoForte();                           
            setKeyFrameFim(4.2f);
            this.tempo = 3.6f;
            tempoVerificador = true;
            golpe = true;
            if(particulas == false && golpe == true){
               Particulas.createParticulas();
               particulas = !particulas;
            }
            return;
         }
      }
      if(parado == true){
         Principal.setKeyFrames(4.5f, 5.1f, 0.5f, Controller.RT_CYCLE);
         parado = !parado;
         return;
      }
      else{return;}
   }



public void socoFraco(){
      t++;
      System.out.println(t+" soco fraco");
      Principal.setKeyFrames(1.8f, 2.4f, 20, Controller.RT_CLAMP);
   }



public void socoMedio(){
      Principal.setKeyFrames(2.7f, 3.3f, 10, Controller.RT_CLAMP);
   }



public void socoForte(){
      Principal.setKeyFrames(3.6f, 4.2f, 10, Controller.RT_CLAMP);
   }



public void verificaTempoKeyFrame(){
      if(this.tempo > getKeyFrameFim()){
         parado = true;
         golpe = false;
         particulas = false;
         tempoVerificador = false;
      }
   }