PDA

View Full Version : controlling player in Flash game


.chluaid
07-30-2002, 01:15 AM
I've started learning to build games in Flash and have a question regarding onClipEvent (enterFrame)

I have a test character whose animation is controlled by arrow-key presses and currently his mc code goes like this..


onClipEvent (enterFrame){
if (Key.isDown(Key.RIGHT) && Key.isDown(Key.UP)) {
gotoAndPlay ("leap");
}
}



It all works fine, as you can see here (http://www.oohbitey.com/bitey/player.html), but you'll notice that he only jumps when you release your finger from the UP key. I'd like him to jump immediately the key is pressed, and I'm sure the problem is this: as long as your finger is on the UP key, that line of code is continuously being run, i.e. gotoAndPlay ("leap"); Therefore, he's stuck on the frame labelled 'leap'. When you release your finger however, he jumps away.

Could anyone please tell me how I'd run that piece of code only once? I have tried using a counter variable, but I'm not too good at ActionScript (trying to remedy that) and I'm sure I'm doing everything wrong.

Cheers :D

sumul
07-30-2002, 03:28 AM
You could try something like ...

onClipEvent(enterFrame)
{
if(!leaping)
{
if (Key.isDown(Key.RIGHT) && Key.isDown(Key.UP))
{
leaping = true;
gotoAndPlay("leap");
}
}
}

Then put "leaping = false;" at the end of your leap animation. Of course, if you're using MX, the onKeyDown event would save you some trouble.

.chluaid
07-30-2002, 07:37 AM
thanks for your help :)
your advice was great and I've got it working now..

the bit I don't understand about your reply was the Flash MX onKeyDown event.. Yes I am using Flash MX, but could you tell me something about onKeyDown please? I had no idea it existed.

farafiro
07-30-2002, 07:50 AM
Originally posted by .chluaid
.. Yes I am using Flash MX, but could you tell me something about onKeyDown please? I had no idea it existed.

http://www.actionscript.org/tutorials/intermediate/Flash_MX_Event_Model/index.shtml

.chluaid
07-30-2002, 08:37 AM
cheers farafiro

reading now :D