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

Why won't my player move

New Here ,
Feb 12, 2013 Feb 12, 2013

So i'm starting a new game (more of a benchmark for myself really though) to test how well I remember the material. So I had planned to test it bit by bit but I can't event get my player to move! I realize in a scroller you move the background mainly, not the player, but before I did that I tested to see if my player would move. He wouldn't. I'm not getting any errors, warning, output readings. Any ideas?

package

{

          import flash.display.MovieClip;

          import flash.events.Event;

          import flash.ui.Keyboard;

          import flash.events.MouseEvent;

          import flash.events.KeyboardEvent;

          public class Main extends MovieClip

          {

                    var vx:int;

                    public function Main()

                    {

                              init();

                    }

                    function init():void

                    {

                              //initilize variables

                              vx = 0;

                              //add Event Listeners

                              stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);

                              stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);

                              addEventListener(Event.ENTER_FRAME, onEnterFrame);

                    }

                    function onKeyDown(event:KeyboardEvent):void

                    {

                              if (event.keyCode == Keyboard.LEFT)

                              {

                                        vx = -5;

                              }

                              else if (event.keyCode == Keyboard.RIGHT)

                              {

                                        vx = 5;

                              }

                    }

                    function onKeyUp(event:KeyboardEvent):void

                    {

                              if (event.keyCode == Keyboard.LEFT || event.keyCode == Keyboard.RIGHT)

                              {

                                        vx = 0;

                              }

                    }

                    function onEnterFrame(event:Event):void

                    {

                     //Move the player

                    player.x +=  vx;

                    }

          }

}

TOPICS
ActionScript
318
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
Community Expert ,
Feb 12, 2013 Feb 12, 2013
LATEST

use the trace function to see if vx is changing when you use your left and right keys.

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