Be a Supporter!

A moment of invinciblity...

  • 330 Views
  • 6 Replies
New Topic Respond to this Topic
HappyBlack
HappyBlack
  • Member since: Jul. 30, 2010
  • Offline.
Forum Stats
Member
Level 07
Art Lover
A moment of invinciblity... 2011-02-26 11:31:38 Reply

Hello. I've got a small problem, which stops me from doing my next game...
I want to make my hero invincible for 2secs after he is hit by a bullet.
My code for player is (of course it is in onEnterFrame):

if (hit) {
		waiting = function(){
		hit = false;
		}
	}
		bleh = setInterval(waiting, 2000);

And for the bullet:

if (this.hitTest(_root.player)) {
		if(_root.player.hit == false){
		_root.player.hit = true;
                }
                }

And it works.
But only one time.
If the bullet touches me second time, my hero is hit as long as the bullet touches him, not these 2 secs I wanted.
Does anyone know, what to do?
I hope You will understand me ;)

HappyBlack
HappyBlack
  • Member since: Jul. 30, 2010
  • Offline.
Forum Stats
Member
Level 07
Art Lover
Response to A moment of invinciblity... 2011-03-01 10:23:06 Reply

Anyone?

Tygerman
Tygerman
  • Member since: Aug. 16, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to A moment of invinciblity... 2011-03-01 10:41:38 Reply

you need to clearInterval(); when you're done being invincible


BBS Signature
HappyBlack
HappyBlack
  • Member since: Jul. 30, 2010
  • Offline.
Forum Stats
Member
Level 07
Art Lover
Response to A moment of invinciblity... 2011-03-03 08:55:00 Reply

At 3/1/11 10:41 AM, Tygerman wrote: you need to clearInterval(); when you're done being invincible

But where should I add it?
I tried here:

if (hit) {
		waiting = function(){
		hit = false;
                <strong>clearInterval(bleh);</strong>
		}
	}
		bleh = setInterval(waiting, 2000);

But it didn't work.

HappyBlack
HappyBlack
  • Member since: Jul. 30, 2010
  • Offline.
Forum Stats
Member
Level 07
Art Lover
Response to A moment of invinciblity... 2011-03-03 08:56:06 Reply

Sorry for <*strong> , I thought it can be used in code...
Why isn't there 'Preview' option?
;)

potatopower
potatopower
  • Member since: Feb. 24, 2010
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to A moment of invinciblity... 2011-03-03 12:47:40 Reply

you're clearing the interval before he turns invincible >.>
You need to make it so that after the 2 seconds, in a function, put invincible = false and clearInterval(bleh)
I think that's clear interval for as2, or maybe it's bleh.clearInterval(); idk...


AS3 programmer.
Learn AS3, it's for your own good.

HappyBlack
HappyBlack
  • Member since: Jul. 30, 2010
  • Offline.
Forum Stats
Member
Level 07
Art Lover
Response to A moment of invinciblity... 2011-03-04 08:46:09 Reply

So here it is:

if (hit) {
		invincible = true;
		hit = false;
		waiting = function(){
		invincible = false;
		clearInterval(bleh);
		}
	}
		bleh = setInterval(waiting,2000);

Still doesn't work more than once.
Maybe I'm just so silly, that I don't understand, what you are trying to say ;x