Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Thread Tools Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
Old 12-19-2010, 10:09 PM   #1
Registered User
Join Date: Dec 2010
Posts: 2
Default [AS3] How do i make a character move and turn using arrow keys?

I'm really terrible with actionscript and no matter where i look i just cant seem to find a tutorial for as3 in which it explains how to make an animated character move and turn using the arrow keys. Would appreciate any help i can get or even a link to a tutorial if anyone has found a good one. Thanks!
rawrimarabbit is offline   Reply With Quote
Old 12-19-2010, 10:47 PM   #2
Senior Member
Join Date: Sep 2008
Posts: 223

Very simple setup here. I made a object and made it a symbol and converted to symbol(named it Ball). Then exported it for ActionScript.

I then made a actionscript file and named it Main.as and insterted the following under.

ActionScript Code:
package {     import flash.display.Sprite;     import flash.events.Event;     import flash.ui.Keyboard;     import flash.events.KeyboardEvent;         public class Main extends Sprite     {         private var ball:Ball;         private var speed:Number = 5;         public function Main ():void         {                         ball = new Ball();             ball.x = stage.stageWidth/2;             ball.y = stage.stageHeight/2;             addChild(ball);             stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyDown);         }         private function KeyDown (key:KeyboardEvent):void         {             switch(key.keyCode)             {                 case Keyboard.LEFT:                 ball.x -= speed;                 break;                                 case Keyboard.RIGHT:                 ball.x += speed;                 break;                                 case Keyboard.UP:                 ball.y -= speed;                 break;                                 case Keyboard.DOWN:                 ball.y += speed;                 break;             }                     }     } }

Bare in mind that this is NOT the best way to do it. It is just a simple way to get you started.

If you want to have more smooth flow in the movement and add some physic, check out Foundation Actionscript 3.0 Animation: Making Things Move! great book to start with.

Good luck with your scripting!
franky87 is offline   Reply With Quote
Old 12-19-2010, 11:00 PM   #3
Registered User
Join Date: Dec 2010
Posts: 2

thanks so much! this is an awesome starting point for me to work from ^_^
rawrimarabbit is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 05:13 PM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.