PDA

View Full Version : timer for recently hit function


phinnycupcakes
12-25-2008, 06:04 AM
So I want to add a recently hit function that basically gives you invincibility for 2 seconds after you get hit.

I've got a recentlyHit boolean in my char's class, and implementation so far works perfectly

this is what i have so far... definitely not much
function charHit ()
{
if(recentlyHit)
{
_root.char._alpha = 50;
// WAIT 2 SECONDS
recentlyHit = false;
}


}

So... guess what I want =P
I was thinking of maybe using setInterval,
but this method is in an onEnterFrame part for my playercharacter movieclip. And yeah, I want to be able to move still, I just want a timer going in the background that sets off when you get hit.. Thats all.

shouldn't be too difficult.

orange gold
12-25-2008, 04:40 PM
_root.onEnterFrame = function() {
function wait() {
trace("sucess");
// your code here
myTimer = setInterval(wait, 2000); // 1 second = 1000, i have it set to 2000 for 2 seconds
}

orange gold
12-25-2008, 04:43 PM
full code


_root.onEnterFrame = function() {
function charHit ()
{
if(recentlyHit)
{
_root.char._alpha = 50;
function wait() {
recentlyHit = false;
// your other code(s) here
myTimer = setInterval(wait, 2000); // 1 second = 1000, i have it set to 2000 for 2 seconds
}
}
}
}