Skip to content

Conversation

RapperGF
Copy link

Currently, in HaxeFlixel, attempting to batch multiple FlxSprites with color transforms causes batching to break.
If any sprite has a color that is not pure white, it will batch. This causes sprites to be drawn in separate colored batches, even if the color is set.

This PR changes the default color of sprites to FlxColor.TRANSPARENT (effectively zero tinting) while still respecting all colors, including FlxColor.WHITE

With this change:

  • Sprites set to FlxColor.WHITE will be batched together without altering their original colors.
  • Sprites without a color (or with FlxColor.TRANSPARENT) will render with no tint, restoring previous behavior.

Previous Behavior:

image

New Behavior:

image

Example project:

package;

import flixel.FlxG;
import flixel.FlxSprite;
import flixel.util.FlxColor;
import flixel.group.FlxSpriteGroup;

class ColoringTest extends flixel.FlxState {

    var grp:FlxSpriteGroup;

    override public function create() {
        grp = new FlxSpriteGroup();

        var sprW = 16;
        var sprScale = 5;
        var spacing = sprW * sprScale;

        var screenW = FlxG.width; 
        var spritesPerRow = Math.floor(screenW / spacing);

        var totalSprites = 60;

        for (i in 0...totalSprites) {
            var row = Math.floor(i / spritesPerRow);
            var col = i % spritesPerRow;

            var spr = new FlxSprite(col * spacing, 20 + row * spacing);
            spr.scale.set(sprScale, sprScale);

            if (i == 0) {
                // First sprite is always white
                spr.color = FlxColor.WHITE;
            } else {
                // 20% chance to be white, otherwise random color
                if (Math.random() < 0.2) {
                    spr.color = FlxColor.WHITE;
                } else {
                    spr.color = FlxColor.fromRGB(
                        Std.int(Math.random() * 256),
                        Std.int(Math.random() * 256),
                        Std.int(Math.random() * 256)
                    );
                }
            }

            grp.add(spr);
        }

        grp.screenCenter();
        add(grp);
    }
}

- Defaults all FlxSprites to Transparent tinting which indicates ZERO tint.

- Adds the ability for all sprites to batch with any color.

- To disable a color tint set the color property to 0x00000000
@LeonGamerPS1
Copy link
Contributor

fire 🔥

var isColored = (transform != null #if !html5 && transform.hasRGBMultipliers() #end);
var isColored:Bool = false;
if(transform != null) {
if(#if !html5 transform.hasRGBMultipliers() #else true #end || colored)
Copy link
Contributor

@Vortex2Oblivion Vortex2Oblivion Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cant you just like

isColored = #if !html5 transform.hasRGBMultipliers()  ||  #end  colored;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you can! I did it like a separated if for clarity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants