Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to make a stick man running when pressing a key?

New Here ,
Oct 30, 2013 Oct 30, 2013

I created a movieclip named stickman. In that, I created an animation by drawing a sequence of move in everyframe, so that stickman can run. Now what I want is that when I press a key, the stick man will run from left to right and when I release the key, it will stop. This is my code:

RunningMan.stop();

stage
.addEventListener(KeyboardEvent.KEY_DOWN,keypresseddown);
function keypresseddown(event:KeyboardEvent😞void
{

var key:uint = event.keyCode;
switch (key) {
  
case Keyboard.LEFT :
  
{
      
RunningMan.play();
      
RunningMan.x-=10;
      
RunningMan.scaleX=-1;
      

  
};
   
case Keyboard.RIGHT :
   
{
       
RunningMan.play();  //play animated run
       
RunningMan.x+=10;
       
RunningMan.scaleX=1;
       

   
};
   
default: RunningMan.stop();
  
}
}

However, when I pressed and held a key, it moved from left to right without animated run.

How can I fix it? Thanks in advance.


TOPICS
ActionScript
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Oct 31, 2013 Oct 31, 2013

case conditions need a break() statement at the end:

switch (key) {
  
case Keyboard.LEFT :
      
RunningMan.play();
      
RunningMan.x-=10;
      
RunningMan.scaleX=-1;
       break();

   
case Keyboard.RIGHT :
       
RunningMan.play();  //play animated run
       
RunningMan.x+=10;
       
RunningMan.scaleX=1;
        break();
   
default: RunningMan.stop();break();
  
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 01, 2013 Nov 01, 2013

Thanks, but when I pressed a key, the man moved without animation.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Nov 03, 2013 Nov 03, 2013
LATEST

Make sure that the animatuion (the running part) is triggered with Runningman.play().

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines