Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Sprite animation play just one time at one click


masa
 Share

Recommended Posts

I'm creating action game like FinalFight by capcom.

When I touch button , I want punch animation play just one time.

 

but in my case, punch aniamtion is looping, while I keep pressing button. 

 

how can I solve it.

thanks.

function create(){// Create virtual controller        buttonA = game.add.button(600, 400, 'buttonA', null, this, 0, 1, 0, 1);        buttonA.fixedToCamera = true;        buttonA.events.onInputOver.add(function(){punch=false;});        buttonA.events.onInputOut.add(function(){punch=false;});        buttonA.events.onInputDown.add(function(){punch=true;});        buttonA.events.onInputUp.add(function(){punch=false;});}function update(){if(punch)        {            player.animations.play("punch", 9, false);        }   }
 

post-14478-0-69032200-1431149895.png

Link to comment
Share on other sites

When the player holds the punch button down your code sets "punch" to true. That means that it'll keep playing the punch animations for as long as the player is holding the button down, regardless of whether that last argument is false or not. The code in your update method makes sure of that.

 

You probably need to do something where you set punch to false after you start the animation playing, maybe?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...