HaxeFlixel Logo HaxeFlixel Snippets
  • About
  • Tutorials
  • Back to HaxeFlixel.com
  • Basics
    • Screen
    • Adding
  • Objects
    • Alive
    • Health
  • Sprites
    • Making Sprites
    • Loading Sprites
    • Animation
    • Alpha
    • Color
    • Facing
    • Scale
    • Baked Rotations
  • Text
    • FlxText
    • FlxBitmapText
  • Movement
    • Velocity
    • Acceleration
    • MaxVelocity
    • Gravity
    • Jumping
    • Angle
    • Angular Velocity
    • Angular Acceleration
  • Groups
    • Basic Group
    • Typed Group
    • Recycling
  • Tiling
    • Tileblock
    • Tilemap
  • Overlap
    • Simple Overlap
    • Overlap Callbacks
  • Collision
    • 1-to-1 Collision
    • Immovable
    • Tilemap Collision
    • Moving Platforms
  • Camera
    • Flash
    • Fade
    • Shake
    • Follow
  • Input
    • Basics
    • Keyboard
    • Mouse
    • Button
  • Sound
    • FlxSound

Color

Use the color property of a FlxSprite to tint a sprite’s graphic to a specific color. This applies the color to the whole graphic uniformly.

// sprite will be tinted red
sprite.color = 0xff0000;

Demonstration

Source

source/PlayState.hx

package;

import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.util.FlxColor;

class PlayState extends FlxState
{
    var hue:Float = 0;
    var sprite:FlxSprite;

    override public function create()
    {
        super.create();

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

    override public function update(elapsed:Float)
    {
        hue += elapsed * 50;
        if (hue > 360)
            hue -= 360;

        var color = FlxColor.fromHSB(Std.int(hue), 1, 1);
        sprite.color = color;

        super.update(elapsed);
    }
}
View Source on GitHub

Tags

sprites graphics
  1. Home
  2. Sprites
  3. Color
Powered By HaxeFlixel Logo HaxeFlixel