motion control

0

I have a sprite with 3 different states 'run', 'stop', 'wait'. Pressing the left or right arrow of the keyboard activates the running animation, if they are not active, 'wait' is executed, what I need is to run 'stop' without a loop, just when the right or left keys are released, and then run the 'wait' loop

this is my code to call the character sprite

    //llamamos sprites
    this.miniMika=this.game.add.sprite(700,200, 'miniMika', 39); 
   //llamamos archivo y especificamos coordenadas y frame inicial
    this.miniMika.anchor.setTo(0.5); //pivote  en el centro
    this.miniMika.animations.add('correr', [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19],29,true);//frames, frames/seg, loop
    this.miniMika.animations.add('parar',[20,21,22,23,24,25,26,27,28],29, false); 
    this.miniMika.animations.add('esperar',[29,30,31,32,33,34,35,36,37,39],29,true);

    this.game.physics.arcade.enable(this.miniMika);
    this.game.camera.follow(this.miniMika); 

This is the motion control

    //Actualiza durante el juego
update: function(){

    //controles de movimineto
    this.miniMika.body.velocity.x=0;
    if(this.cursor.left.isDown){
      this.miniMika.body.velocity.x= -this.RUNNING_SPEED;
      this.miniMika.scale.setTo(-1, 1);
      this.miniMika.play('correr');
    }else if(this.cursor.right.isDown){
      this.miniMika.body.velocity.x= this.RUNNING_SPEED;
      this.miniMika.scale.setTo(1, 1);
      this.miniMika.play('correr');
    }
    else{
        this.miniMika.play('parar');
        this.miniMika.play('esperar';)
    }

The result is that when you stop 'running' you go to 'wait' and you ignore 'stop'

    
asked by mmcuervo 25.03.2018 в 19:24
source

0 answers