A Flash Developer Resource Site

Results 1 to 17 of 17

Thread: Making a character flicker alpha to 0 then 100

  1. #1
    Robot Master the--flash's Avatar
    Join Date
    Jul 2005
    Location
    The year 20XX...
    Posts
    132

    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.

  2. #2
    Senior Member
    Join Date
    Dec 2005
    Posts
    426
    you could use set interval or something
    Code:
    flicker=false;
    
    function flicker()
    {
    if(flicker)
    {
    player._alpha=0;
    }else
    {
    player._alpha=100;
    }
    flicker=!flicker;
    }

  3. #3
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    or
    PHP Code:
    function flicker()
        
    player._visible = !player._visible;
    }
    _root.onEnterFrame flicker

  4. #4
    Senior Member
    Join Date
    Mar 2008
    Posts
    301
    PHP Code:
    function flicker()
        
    player._alpha = -player._alpha+100;
    }
    _root.onEnterFrame flicker

  5. #5
    Senior Member
    Join Date
    Dec 2005
    Posts
    426
    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]
    }

  6. #6
    Senior Member
    Join Date
    Mar 2008
    Posts
    301
    PHP Code:
    function flicker()
        
    player._alpha 50 50*Math.cos(getTimer()/100);
    }
    _root.onEnterFrame flicker

  7. #7
    Heli Attack! iopred's Avatar
    Join Date
    Jun 2003
    Location
    Sydney, Australia
    Posts
    923
    PHP Code:
    function flicker()
        
    player._alpha = (player._alpha == 100?0:100);
    }
    _root.onEnterFrame flicker
    Christopher Rhodes
    squarecircleco.

  8. #8
    Robot Master the--flash's Avatar
    Join Date
    Jul 2005
    Location
    The year 20XX...
    Posts
    132
    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.

  9. #9
    file not found Captain_404's Avatar
    Join Date
    Apr 2006
    Posts
    457
    Quote 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...

  10. #10
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    this is fun, another one:
    PHP Code:
    function flicker() 
        
    player._alpha getTimer()%100

    _root.onEnterFrame flicker

  11. #11
    Heli Attack! iopred's Avatar
    Join Date
    Jun 2003
    Location
    Sydney, Australia
    Posts
    923
    function flicker()
    player._alpha = random(100);
    }
    _root.onEnterFrame = flicker;

    could look pretty
    Christopher Rhodes
    squarecircleco.

  12. #12
    Senior Member
    Join Date
    Mar 2008
    Posts
    301
    PHP Code:
    function flicker()
        
    player._alpha 2*Math.abs(getTimer()%100-50);
    }
    _root.onEnterFrame flicker

  13. #13
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    just to prove that there is yet another way
    PHP Code:
    setInterval( function(){ player._visible=!player._visible }, 200 ); 

  14. #14
    Senior Member
    Join Date
    Mar 2008
    Posts
    301
    PHP Code:
    alphaArray = new Array;
    alphaArray[0] = 100;
    alphaArray[100] = 0;
    function 
    flicker()
        
    player._alpha alphaArray[player._alpha];
    }
    _root.onEnterFrame flicker

  15. #15
    Senior Member
    Join Date
    Mar 2008
    Posts
    301
    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

  16. #16
    Senior Member
    Join Date
    Mar 2008
    Posts
    301
    PHP Code:
    function flicker() {
        
    player._alpha ^= 100;
    }
    _root.onEnterFrame flicker

    I like this one

  17. #17
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center