Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 03-02-2009, 03:10 AM   #1
Zend
Registered User
 
Join Date: Jan 2009
Posts: 16
Angry [AS3] Character Movement

I'm very confused.. I've reviewed and reviewed and reviewed my code and I can't find any problems. But for some reason my guy will only move 5 pixels away and stop, but when I release the arrow key he will return to his original position.

I know it's long and probably looks very intimidating, but if someone can check out my code and see if they know whats wrong I would be forever grateful. There is a downloadable preview of my project attached to this thread.

Zend is offline   Reply With Quote
Old 03-02-2009, 03:22 AM   #2
runawayprisoner
ActionScripted
 
Join Date: Nov 2008
Posts: 94
Default

Well, here's the culprit:

ActionScript Code:
function levelCheck(event:Event):void{     if (currentFrame < 5){         currentLevel = currentFrame;         prevLevel = currentFrame - 1;         oneTime();     } } function oneTime():void{     if (currentLevel > prevLevel){         positionReset();         prevLevel += 1     } }

Since the currenFrame is always less than 5, it always does the currentLevel = currentFrame and then prevLevel = currentFrame - 1 operations.

Then goes on to check oneTime.

Guess what? prevLevel would ALWAYS be less than currentLevel because of the above 2 operations, so it just resets your character's position every single time infinitely.

I'm not too sure what you'd like to do here, so I'd leave the fixing to you. But the game works fine if you take out the listener and those two functions, then proceed as usual, reach the goal, and the win screen comes up.

Also, try to use multiple booleans so you can recognize multiple key presses at the same time instead of just one keyCode at a time (1 key press at a time).

...I think I might well write a tutorial on that because there has been a fair amount of people asking about how to recognize more than 2 key presses at the same time.
runawayprisoner is offline   Reply With Quote
Old 03-02-2009, 03:31 AM   #3
Zend
Registered User
 
Join Date: Jan 2009
Posts: 16
Smile

Oh, so basically you saying that because currentFrame is always less then 5 it will always be making prevLevel 1 less then currentLevel even though I have prevLevel += 1; in the function oneTime? So it infinitely resets his position?

Well what I'm trying to do is make it so the function still works in the upcoming levels. That way it will reset his position in the next level as well. I already tried taking that function and just inserting it into the next frame since I don't plan on adding any levels after that but it would do the function winLose first and continue to the Congratulations frame before you got a chance to even play the second level.

Sorry if that didn't make a whole lot of sense, this stuff is hard to explain :\

But thanks so much for the help I'll see what I can do to fix it.

[Edit]
Fixed it, thanks again for the help
Zend is offline   Reply With Quote
Reply


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
[AS3] Character Movement PurpleZ Gaming and Game Development 15 02-28-2009 02:38 PM
[AS3] Character movement Suikoten Gaming and Game Development 6 01-26-2009 01:01 PM
[AS3] Character movement Duh Star Gaming and Game Development 3 01-14-2009 10:10 PM
[AS3] Help with Character Movement (Possibly Referencing MCs??) e1337idiot Gaming and Game Development 1 07-31-2008 03:13 AM
[AS3] Character movement Gridden Gaming and Game Development 6 09-26-2006 10:43 PM


All times are GMT. The time now is 10:40 AM.

///
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.