From 213388970e73531e87ab83b9a5ee3fe77bf088b4 Mon Sep 17 00:00:00 2001 From: Rapper GF <84131849+RapperGF@users.noreply.github.com> Date: Sun, 28 Sep 2025 13:28:06 -0400 Subject: [PATCH] Patch Sprite Color Batching and Default Colors - 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 --- flixel/FlxCamera.hx | 8 ++++++-- flixel/FlxSprite.hx | 31 +++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index df97c6d384..6a67090b63 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -745,7 +745,7 @@ class FlxCamera extends FlxBasic } } - public function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, ?smoothing:Bool = false, + public function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?colored:Bool, ?blend:BlendMode, ?smoothing:Bool = false, ?shader:FlxShader):Void { if (FlxG.renderBlit) @@ -765,7 +765,11 @@ class FlxCamera extends FlxBasic } else { - 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) + isColored = true; + } var hasColorOffsets:Bool = (transform != null && transform.hasRGBAOffsets()); #if FLX_RENDER_TRIANGLE diff --git a/flixel/FlxSprite.hx b/flixel/FlxSprite.hx index ea003d3b35..6ff1658461 100644 --- a/flixel/FlxSprite.hx +++ b/flixel/FlxSprite.hx @@ -262,9 +262,10 @@ class FlxSprite extends FlxObject /** * Multiplies this sprite's image by the given red, green and blue components, alpha is ignored. * To change the opacity use `alpha`. Calling `setColorTransform` will also change this value. + * defaults to flixel.FlxColor.TRANSPARENT for zero tint, to tint a sprite use a non transparent color. * @see https://snippets.haxeflixel.com/sprites/color/ */ - public var color(default, set):FlxColor = FlxColor.WHITE; + public var color(default, set):FlxColor = FlxColor.TRANSPARENT; /** * The color effects of this sprite, changes to `color` or `alpha` will be reflected here @@ -367,6 +368,12 @@ class FlxSprite extends FlxObject @:noCompletion var _facingFlip:Map = new Map(); + /** + * Tells this `FlxSprite` to batch any color Tint that is not `flixel.FlxColor.TRANSPARENT` + */ + @:noCompletion + var _colored:Bool; + /** * Creates a `FlxSprite` at a specified position with a specified one-frame graphic. * If none is provided, a 16x16 image of the HaxeFlixel logo is used. @@ -440,6 +447,7 @@ class FlxSprite extends FlxObject graphic = null; _frame = FlxDestroyUtil.destroy(_frame); _frameGraphic = FlxDestroyUtil.destroy(_frameGraphic); + _colored = false; shader = null; } @@ -898,7 +906,7 @@ class FlxSprite extends FlxObject matrix.ty = Math.floor(matrix.ty); } - camera.drawPixels(frame, framePixels, matrix, colorTransform, blend, antialiasing, shader); + camera.drawPixels(frame, framePixels, matrix, colorTransform, _colored, blend, antialiasing, shader); } /** @@ -1537,12 +1545,19 @@ class FlxSprite extends FlxObject @:noCompletion function set_color(value:FlxColor):Int - { - if (color == value) - return value; - - color = value; - updateColorTransform(); + { + if(value == FlxColor.TRANSPARENT) { + _colored = false; + color = FlxColor.TRANSPARENT; + } else { + if (color == value) + { + return value; + } + color = value; + updateColorTransform(); + _colored = true; + } return color; }