Be a Supporter!

AS2 Flicker effect?

  • 78 Views
  • 7 Replies
New Topic Respond to this Topic
jaypeps
jaypeps
  • Member since: Nov. 5, 2014
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
AS2 Flicker effect? 2014-12-21 19:14:34 Reply

Im trying to get my character to flicker when he gets hit by the enemy, im looking to have it on a timer so that he flickers for about 5 seconds(during which time he cannot be hit by the enemy) and then goes back to his original state. I know its a lot to ask but any ideas on how to do this?

Etherblood
Etherblood
  • Member since: Apr. 14, 2013
  • Offline.
Forum Stats
Member
Level 12
Game Developer
Response to AS2 Flicker effect? 2014-12-21 20:13:12 (edited 2014-12-21 20:16:58) Reply

At 12/21/14 07:14 PM, jaypeps wrote: Im trying to get my character to flicker when he gets hit by the enemy, im looking to have it on a timer so that he flickers for about 5 seconds(during which time he cannot be hit by the enemy) and then goes back to his original state. I know its a lot to ask but any ideas on how to do this?

Just invert the visible property of your character each frame as long as the effect is active. (or every x frames)
I don't know if as2 has timers, if it has them, just set the effect, start the timer, and remove the effect and make the character visible on timeout.

D-SuN
D-SuN
  • Member since: Jan. 4, 2004
  • Offline.
Forum Stats
Supporter
Level 16
Game Developer
Response to AS2 Flicker effect? 2014-12-21 20:18:14 Reply

At 12/21/14 07:14 PM, jaypeps wrote: Im trying to get my character to flicker when he gets hit by the enemy, im looking to have it on a timer so that he flickers for about 5 seconds(during which time he cannot be hit by the enemy) and then goes back to his original state. I know its a lot to ask but any ideas on how to do this?

This should do it. It's not tied to a 'timer', but a counting variable.

onClipEvent (load) {
	//Counter
	//When the flickerTimer is on 0, the clip should no longer flicker.
	//If the flickerTimer is greater than 0, the flickerTimer will -1 until it's 0. During this, the clip will flicker.
	var flickerTimerDefult:Number = 150;
	var flickerTimer:Number = flickerTimerDefult;
}

onClipEvent (enterFrame) {
	if (flickerTimer > 0) {
		flickerTimer --;
		//%2 figures if the flickerTimer is a odd or even number.
		if (flickerTimer%2 == 1) {
			//odd
			this._visible = false;
		} else {
			//even
			this._visible = true;
		}
	} else {
		//Should no longer flicker, make visible just incase
		this._visible = true;
	}
}
jaypeps
jaypeps
  • Member since: Nov. 5, 2014
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to AS2 Flicker effect? 2014-12-23 15:04:46 Reply

Hi guys thanks for the response. D-Sun i tried your code and it works great the only problem im having is getting the character to go back to visible, for some reason the last statement isnt working. Also is there a way i could get the count to continue after a hitTest.

what im trying to do is this.

Enemy hits the character.
blinking is triggered.
blinking continues on for a few seconds after the hittest.
while blinking the character is invincible.

I was thinking would i be better off creating a duplicate character and when the enemy hits the original character unload that and load the duplicate replacement to its x and y.
this way i could add the blink to the duplicate like what Etherblood said and remove the hittest effect from the duplicate so hes invincible.
has anyone tried this?

D-SuN
D-SuN
  • Member since: Jan. 4, 2004
  • Offline.
Forum Stats
Supporter
Level 16
Game Developer
Response to AS2 Flicker effect? 2014-12-23 21:46:25 Reply

Strange, the code should set the player back to visible after that flickering is done, works on my end.

onClipEvent (load) {
	//Counter
	//When the flickerTimer is on 0, the clip should no longer flicker.
	//If the flickerTimer is greater than 0, the flickerTimer will -1 until it's 0. During this, the clip will flicker.
	var flickerTimerDefult:Number = 100;
	var flickerTimer:Number = 0;

	var hurt:Boolean = false;
	
}

onClipEvent (enterFrame) {
	
	if (!hurt) {
		//for testing, space key will trigger player damage
		if (Key.isDown(Key.SPACE)) {
			flickerTimer = flickerTimerDefult;
			hurt = true;
		}
	}
	
	if (hurt) {
		if (flickerTimer > 0) {
			flickerTimer --;
			//%2 figures if the flickerTimer is a odd or even number.
			if (flickerTimer%2 == 1) {
				//odd
				this._visible = false;
			} else {
				//even
				this._visible = true;
			}
		} else {
			//Should no longer flicker, make visible just incase
			this._visible = true;
			hurt = false;
		}
	}
}

I added in some functionality for damage. If you hit SPACE, it will simulate damage. So he can only be damaged when his hurt variable is set to false. Once its damaged, hurt is true - so now he cannot be damaged again until hurt is set back to false.
Once damaged, it runs the flickering code. Once the flicker is complete, he should be set to visible and hurt to false.

No need for two separate characters, managing 1 character should be easier in the long run. You wouldn't want to continue to update the graphics for two characters, something like that. Let me know if it works.

jaypeps
jaypeps
  • Member since: Nov. 5, 2014
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to AS2 Flicker effect? 2014-12-24 10:24:58 Reply

Hey D-SuN thanks for this it works perfectly. I discovered that the problem with the blinking not turning off was because i had the code on my enemy and when i killed my enemy while blinking the enemy was removed thus removing the code leaving the character either in a visible or invisible state. So i have put the code on my character and all is 100%. Thanks a mill.

I was wondering is it possible to refer to a layer and its contents on a hittest?
ive named the layer enemies and all the enemies are on it in separate MCs
i probably should have put my enemies into a container and refer to its instance name...

anyway thanks a lot for your help.
kudos.

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to AS2 Flicker effect? 2014-12-24 10:54:01 Reply

At 12/24/14 10:24 AM, jaypeps wrote: Hey D-SuN thanks for this it works perfectly. I discovered that the problem with the blinking not turning off was because i had the code on my enemy and when i killed my enemy while blinking the enemy was removed thus removing the code leaving the character either in a visible or invisible state. So i have put the code on my character and all is 100%. Thanks a mill.

Why would you put code that controls the player on an enemy, anyway? Seems a bit silly to, for an analogy, use my refrigerator to control my house's heating when there's a perfectly good thermostat willing to do the job.
Especially since refrigerators get replaced. Would be a giant pain in the ass to have to uninstall and reinstall the heating mechanism every few years when I get new fridges.


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
jaypeps
jaypeps
  • Member since: Nov. 5, 2014
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to AS2 Flicker effect? 2014-12-24 11:50:39 Reply

I have a few fridges that run off the heating system. I buy one every week and they work 110%