PDA

View Full Version : one-at-a-time



kpxnamja
June 12th, 2006, 07:57 PM
hello, here's my problem: I have a faux animation of a red square which appears to have a slight resemblance of a human (2 eyes and one mouth), and is holding a rectangular bat. I'm trying to make it swing- once. The thing is, everytime the gamer presses the left mouse button the square swings. So if a gamer presses the left moust rapidly, it is doing a rapid fire swing- cheaters.

So here's what I tried: I tried to create a boolean, if idle = true, then one could swing, if not, cannot.

Here's the source file:

Aesir
June 12th, 2006, 10:09 PM
This is what I would do, but it is a pretty odd way of doing it.

Make a variable called cooldown...

onClipEven (load) {
var cooldown:Number = 0
}

...and...

onClipEvent (enterFrame) {
if (cooldown > 0) {
cooldown -= 1
}
}

...so that the cooldown counts down to zero. Also, in the attack function have something like...

if (cooldown = 0) {
attackFunction()
cooldown = 100
}

...so that you can only attack when cooldown is cooled down. You should also change the maximum number (100) to something else, probably a function of the framerate so that you can have a definite attack rate.

kpxnamja
June 13th, 2006, 12:04 AM
hmm... that seems to be an alternative... However, I need it so that it restricts after a mouse click :S

Aesir
June 13th, 2006, 12:58 AM
Under no condition within this file, as it is, should the player be able to swing twice?

You had...

onClipEvent (enterFrame) {
_root.idle = true;
if (Key.isDown(1)){
if (_root.idle == true) {
_root.idle = false;
_root.hero.gotoAndPlay("hit");
}
}
}

But if I am not mistaken, which I probably am, I would have...

onClipEvent (load) {
_root.idle = true;
}
onClipEvent (enterFrame) {
if (Key.isDown(1)){
if (_root.idle == true) {
_root.idle = false;
_root.hero.gotoAndPlay("hit");
}
}
}

Such that the _root.idle = true; is only true at the beginning? Or you could have an object that changes the value of idle when the mouse is clicked. Seems like you know how to do that though. I suppose I don't understand why you need a different method.

kpxnamja
June 13th, 2006, 04:37 PM
Hey Aesir, that seems to have fixed my problem, but if I feel aggressive and begin a rapid click fest with the left mouse after a few good swings- it stops.

Is there any reasons for this error?

Here are the new files: