|
-
Senior Member
AS3 Chracter Movement
Character movement is cake, well it was in AS2. I loved that good old onEnterFrame function days. Well I have to move on. I have the idea on what I want to do, but I'm stuck at what to do. I am writing my code on the time line ( i don't think that this is the best way to do it, but remembering first learning AS2 I used to write code in every movie clip, we learn). I know that I want to some how find out if a key is down and do an action(move).
so far I have a hero moving back and forward (the moving part is right but I want to control this guy)
Code:
/*** hero is a MovieClip in my Library ***/
var herox:hero = new hero();
var speedx:Number = 10;
function init() {
herox.addEventListener(Event.ENTER_FRAME,live);
herox.x=100;
herox.y=200;
}
function live(event:Event) {
if (herox.x>550) {
speedx=speedx*-1;
trace(herox.x);
}
if (herox.x<0) {
speedx=speedx*-1;
trace(herox.x);
}
herox.x+=speedx;
}
init();
addChild(herox);
now I can use addEventListener() and add a keyboardevent but if not like on enterframe its slow.
thanks a lot,
its been one day and I did a hello world, displayed a movieclip from the libary, and made it move. Thanks to you guys. progress is a beautiful thing.
CEO OF
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|