Set the alpha
property of your FlxSprite
to change the opacity of your sprite. Values can be from 0
to 1
.
// sprite's alpha will be set to 0.5 (50% opacity)
sprite.alpha = 0.5;
Set the alpha
property of your FlxSprite
to change the opacity of your sprite. Values can be from 0
to 1
.
// sprite's alpha will be set to 0.5 (50% opacity)
sprite.alpha = 0.5;
package;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
class PlayState extends FlxState
{
var alpha:Float = 1;
var sprite:FlxSprite;
var alphaDir:Int = -1;
override function create()
{
super.create();
sprite = new FlxSprite("assets/bigbox.png");
sprite.screenCenter();
add(sprite);
}
override function update(elapsed:Float)
{
super.update(elapsed);
alpha += 0.02 * alphaDir;
if (alpha > 1)
alphaDir = -1;
else if (alpha < 0)
alphaDir = 1;
sprite.alpha = alpha;
}
}