HaxeFlixel Logo HaxeFlixel Snippets
  • About
  • Back to HaxeFlixel.com
    • Screen
    • Adding
    • Alive
    • Health
    • Making Sprites
    • Loading Sprites
    • Animation
    • Alpha
    • Color
    • Facing
    • Scale
    • Baked Rotations
    • FlxText
    • FlxBitmapText
    • Velocity
    • Acceleration
    • MaxVelocity
    • Gravity
    • Jumping
    • Angle
    • Angular Velocity
    • Angular Acceleration
    • Basic Group
    • Typed Group
    • Recycling
    • Sorting
    • Tileblock
    • Tilemap
    • Ray
    • tileProperties
    • Autotiles
    • Simple Overlap
    • Overlap Callbacks
    • 1-to-1 Collision
    • Immovable
    • Tilemap Collision
    • Moving Platforms
    • Flash
    • Fade
    • Shake
    • Follow
    • scrollFactor
    • Basics
    • Keyboard
    • Gamepad
    • Mouse
    • Button
    • FlxSound
    • FlxState
    • FlxSubState
    • Tween
    • Angle
    • Color
    • Motion
    • Num
    • Callbacks
    • FlxTimer
    • FlxSignal
    • moveTowards
    • Distance
    • velocityFromAngle
    • timeScale
    • drawLine

Alpha

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;

Demonstration

Source

View Source on GitHub

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 public function create()
	{
		bgColor = 0;

super.create();

		sprite = new FlxSprite("assets/bigbox.png");
		sprite.screenCenter();
		add(sprite);
	}

	override public 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;
	}
}

Tags

sprites graphics
Powered By HaxeFlixel Logo HaxeFlixel