-
Robot Master
Making a character flicker alpha to 0 then 100
Hey thar,
I'm making a Super Mario Bros-like game, and when you get hit, you get 3 seconds of "invincible" time until you become vulnerable again. During these 3 seconds, I want to make my character flicker to 0 alpha and then to 100 (to show he's still invincible), but I can't think of how to do it effeciantly. I want to put this in a function that is called every frame...I thought maybe using getTimer() and checking if it's even or odd, but I don't think you can do that in Flash.
Can anyone lend some input?
Thanks in advance,
the--flash.
Last edited by the--flash; 08-11-2008 at 10:01 PM.
-
you could use set interval or something
Code:
flicker=false;
function flicker()
{
if(flicker)
{
player._alpha=0;
}else
{
player._alpha=100;
}
flicker=!flicker;
}
-
or
PHP Code:
function flicker()
player._visible = !player._visible;
}
_root.onEnterFrame = flicker;
-
PHP Code:
function flicker() player._alpha = -player._alpha+100; } _root.onEnterFrame = flicker;
-
Even simpler,
depending on your fps either way would look pretty bad.
What you could try is easing the value so that it is smoother.
Code:
flick=1;
function flicker()
{
if(flick==1)
{
player._alpha+=(0-player._alpha)/2;
if(player._alpha<=2)
{
flick=0;
}
}else{
player._alpha+=(100-player._alpha)/2;
if(player._alpha>=98)
{
flick=1;
}
}
}
this.onEnterFrame=flicker;
[/code]
}
-
PHP Code:
function flicker()
player._alpha = 50 + 50*Math.cos(getTimer()/100);
}
_root.onEnterFrame = flicker;
-
Heli Attack!
PHP Code:
function flicker()
player._alpha = (player._alpha == 100?0:100);
}
_root.onEnterFrame = flicker;
-
Robot Master
Seems like a popular topic.
Thanks for all the replies, I'll try a couple out and see which works best.
EDIT:Aight, went with the _visible one, since I do like simple solutions. It's only 24FPS, and it's a Mario game so I wanted to do it like the old flicker. Thanks again.
Last edited by the--flash; 08-12-2008 at 12:09 AM.
-
file not found
Originally Posted by the--flash
Aight, went with the _visible one
DANGIT! I knew I should have set the _visible property of my post to true!
Nobody ever picks the !visible ones...
-
this is fun, another one:
PHP Code:
function flicker()
player._alpha = getTimer()%100;
}
_root.onEnterFrame = flicker;
-
Heli Attack!
function flicker()
player._alpha = random(100);
}
_root.onEnterFrame = flicker;
could look pretty
-
PHP Code:
function flicker()
player._alpha = 2*Math.abs(getTimer()%100-50);
}
_root.onEnterFrame = flicker;
-
just to prove that there is yet another way
PHP Code:
setInterval( function(){ player._visible=!player._visible }, 200 );
-
PHP Code:
alphaArray = new Array;
alphaArray[0] = 100;
alphaArray[100] = 0;
function flicker()
player._alpha = alphaArray[player._alpha];
}
_root.onEnterFrame = flicker;
-
PHP Code:
alphaArray = new Array; alphaArray[0] = 20; alphaArray[20] = 40; alphaArray[40] = 60; alphaArray[60] = 80; alphaArray[80] = 100; alphaArray[100] = 90; alphaArray[90] = 70; alphaArray[70] = 50; alphaArray[50] = 30; alphaArray[30] = 10; alphaArray[10] = 0; function flicker() player._alpha = alphaArray[player._alpha]; } _root.onEnterFrame = flicker;
-
PHP Code:
function flicker() { player._alpha ^= 100; } _root.onEnterFrame = flicker;
I like this one
-
nice one,
smaler array version:
PHP Code:
function flicker(){
player._visible = [1,0][int(player._visible)];
}
_root.onEnterFrame = flicker;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|