@@ -208,7 +208,10 @@ class FlxSprite extends FlxObject
208208 public var bakedRotationAngle (default , null ): Float = 0 ;
209209
210210 /**
211- * Set alpha to a number between `0` and `1` to change the opacity of the sprite.
211+ * Set alpha to a number between `0` and `1` to change the opacity of the sprite. Calling
212+ * `setColorTransform` will also change this value
213+ *
214+ * **NOTE:** This value is automatically clamped to 0 <= a <= 1
212215 @see https://snippets.haxeflixel.com/sprites/alpha/
213216 */
214217 public var alpha (default , set ): Float = 1.0 ;
@@ -246,7 +249,7 @@ class FlxSprite extends FlxObject
246249 /**
247250 * Change the size of your sprite's graphic.
248251 * NOTE: The hitbox is not automatically adjusted, use `updateHitbox()` for that.
249- * WARNING: With `FlxG.renderBlit`, scaling sprites decreases rendering performance by a factor of about x10!
252+ * ** WARNING:** With `FlxG.renderBlit`, scaling sprites decreases rendering performance by a factor of about x10!
250253 * @see https://snippets.haxeflixel.com/sprites/scale/
251254 */
252255 public var scale (default , null ): FlxPoint ;
@@ -255,19 +258,23 @@ class FlxSprite extends FlxObject
255258 * Blending modes, just like Photoshop or whatever, e.g. "multiply", "screen", etc.
256259 */
257260 public var blend (default , set ): BlendMode ;
258-
261+
259262 /**
260- * Tints the whole sprite to a color (`0xRRGGBB` format) - similar to OpenGL vertex colors. You can use
261- * `0xAARRGGBB` colors, but the alpha value will simply be ignored. To change the opacity use `alpha` .
263+ * Multiplies this sprite's image by the given red, green and blue components, alpha is ignored.
264+ * To change the opacity use `alpha`. Calling `setColorTransform` will also change this value .
262265 * @see https://snippets.haxeflixel.com/sprites/color/
263266 */
264- public var color (default , set ): FlxColor = 0xffffff ;
265-
266- public var colorTransform (default , null ): ColorTransform ;
267+ public var color (default , set ): FlxColor = FlxColor .WHITE ;
268+
269+ /**
270+ * The color effects of this sprite, changes to `color` or `alplha` will be reflected here
271+ */
272+ public var colorTransform (default , null ) = new ColorTransform ();
267273
268274 /**
269275 * Whether or not to use a `ColorTransform` set via `setColorTransform()`.
270276 */
277+ @:deprecated (" useColorTransform is deprecated, use hasColorTransform(), instead" )// 6.1.0
271278 public var useColorTransform (default , null ): Bool = false ;
272279
273280 /**
@@ -394,7 +401,6 @@ class FlxSprite extends FlxObject
394401 scale = FlxPoint .get (1 , 1 );
395402 _halfSize = FlxPoint .get ();
396403 _matrix = new FlxMatrix ();
397- colorTransform = new ColorTransform ();
398404 _scaledOrigin = new FlxPoint ();
399405 }
400406
@@ -428,7 +434,6 @@ class FlxSprite extends FlxObject
428434 _flashRect2 = null ;
429435 _flashPointZero = null ;
430436 _matrix = null ;
431- colorTransform = null ;
432437 blend = null ;
433438
434439 frames = null ;
@@ -1008,7 +1013,7 @@ class FlxSprite extends FlxObject
10081013 dirty = true ;
10091014 return positions ;
10101015 }
1011-
1016+
10121017 /**
10131018 * Sets the sprite's color transformation with control over color offsets.
10141019 * With `FlxG.renderTile`, offsets are only supported on OpenFL Next version 3.6.0 or higher.
@@ -1022,33 +1027,48 @@ class FlxSprite extends FlxObject
10221027 * @param blueOffset The offset for the blue color channel value, in the range from `-255` to `255`.
10231028 * @param alphaOffset The offset for alpha transparency channel value, in the range from `-255` to `255`.
10241029 */
1030+ @:haxe.warning (" -WDeprecated" )
10251031 public function setColorTransform (redMultiplier = 1.0 , greenMultiplier = 1.0 , blueMultiplier = 1.0 , alphaMultiplier = 1.0 ,
10261032 redOffset = 0.0 , greenOffset = 0.0 , blueOffset = 0.0 , alphaOffset = 0.0 ): Void
10271033 {
1028- color = FlxColor .fromRGBFloat (redMultiplier , greenMultiplier , blueMultiplier ).to24Bit ();
1029- alpha = alphaMultiplier ;
1030-
1034+ alphaMultiplier = FlxMath .bound (alphaMultiplier , 0 , 1 );
1035+ @:bypassAccessor color = FlxColor .fromRGBFloat (redMultiplier , greenMultiplier , blueMultiplier , 1.0 );
1036+ @:bypassAccessor alpha = alphaMultiplier ;
1037+
10311038 colorTransform .setMultipliers (redMultiplier , greenMultiplier , blueMultiplier , alphaMultiplier );
10321039 colorTransform .setOffsets (redOffset , greenOffset , blueOffset , alphaOffset );
1033-
1034- useColorTransform = alpha != 1 || color != 0xffffff || colorTransform . hasRGBOffsets ();
1040+ useColorTransform = hasColorTransformRaw ();
1041+
10351042 dirty = true ;
10361043 }
10371044
1045+ @:haxe.warning (" -WDeprecated" )
10381046 function updateColorTransform (): Void
10391047 {
1040- if (colorTransform == null )
1041- return ;
1042-
1043- useColorTransform = alpha != 1 || color != 0xffffff ;
1044- if (useColorTransform )
1045- colorTransform .setMultipliers (color .redFloat , color .greenFloat , color .blueFloat , alpha );
1046- else
1047- colorTransform .setMultipliers (1 , 1 , 1 , 1 );
1048-
1048+ colorTransform .setMultipliers (color .redFloat , color .greenFloat , color .blueFloat , alpha );
1049+ useColorTransform = hasColorTransformRaw ();
1050+
10491051 dirty = true ;
10501052 }
1051-
1053+
1054+ /**
1055+ * Whether this sprite has a color transform, menaing any of the following: less than full
1056+ * `alpha`, a `color` tint, or a `colorTransform` whos values are not the default.
1057+ */
1058+ @:haxe.warning (" -WDeprecated" )
1059+ public function hasColorTransform ()
1060+ {
1061+ return useColorTransform || hasColorTransformRaw ();
1062+ }
1063+
1064+ /**
1065+ * Helper for the non-deprecated component of `hasColorTransform`
1066+ */
1067+ function hasColorTransformRaw ()
1068+ {
1069+ return alpha != 1 || color .rgb != 0xffffff || colorTransform .hasRGBAOffsets ();
1070+ }
1071+
10521072 /**
10531073 * Checks to see if a point in 2D world space overlaps this `FlxSprite` object's
10541074 * current displayed pixels. This check is ALWAYS made in screen space, and
@@ -1209,18 +1229,18 @@ class FlxSprite extends FlxObject
12091229 {
12101230 if (_frame == null || ! dirty )
12111231 return framePixels ;
1212-
1232+
12131233 // don't try to regenerate frame pixels if _frame already uses it as source of graphics
12141234 // if you'll try then it will clear framePixels and you won't see anything
12151235 if (FlxG .renderTile && _frameGraphic != null )
12161236 {
12171237 dirty = false ;
12181238 return framePixels ;
12191239 }
1220-
1221- var doFlipX : Bool = checkFlipX ();
1222- var doFlipY : Bool = checkFlipY ();
1223-
1240+
1241+ final doFlipX = checkFlipX ();
1242+ final doFlipY = checkFlipY ();
1243+
12241244 if (! doFlipX && ! doFlipY && _frame .type == FlxFrameType .REGULAR )
12251245 {
12261246 framePixels = _frame .paint (framePixels , _flashPointZero , false , true );
@@ -1229,20 +1249,20 @@ class FlxSprite extends FlxObject
12291249 {
12301250 framePixels = _frame .paintRotatedAndFlipped (framePixels , _flashPointZero , FlxFrameAngle .ANGLE_0 , doFlipX , doFlipY , false , true );
12311251 }
1232-
1233- if (useColorTransform )
1252+
1253+ if (FlxG . renderBlit && hasColorTransform () )
12341254 {
12351255 framePixels .colorTransform (_flashRect , colorTransform );
12361256 }
1237-
1257+
12381258 if (FlxG .renderTile && useFramePixels )
12391259 {
12401260 // recreate _frame for native target, so it will use modified framePixels
12411261 _frameGraphic = FlxDestroyUtil .destroy (_frameGraphic );
12421262 _frameGraphic = FlxGraphic .fromBitmapData (framePixels , false , null , false );
12431263 _frame = _frameGraphic .imageFrame .frame .copyTo (_frame );
12441264 }
1245-
1265+
12461266 dirty = false ;
12471267 return framePixels ;
12481268 }
@@ -1504,25 +1524,24 @@ class FlxSprite extends FlxObject
15041524 }
15051525
15061526 @:noCompletion
1507- function set_alpha (Alpha : Float ): Float
1527+ function set_alpha (value : Float ): Float
15081528 {
1509- if ( alpha == Alpha )
1510- {
1511- return Alpha ;
1512- }
1513- alpha = FlxMath . bound ( Alpha , 0 , 1 ) ;
1529+ value = FlxMath . bound ( value , 0 , 1 );
1530+ if ( alpha == value )
1531+ return value ;
1532+
1533+ alpha = value ;
15141534 updateColorTransform ();
15151535 return alpha ;
15161536 }
15171537
15181538 @:noCompletion
1519- function set_color (Color : FlxColor ): Int
1539+ function set_color (value : FlxColor ): Int
15201540 {
1521- if (color == Color )
1522- {
1523- return Color ;
1524- }
1525- color = Color ;
1541+ if (color == value )
1542+ return value ;
1543+
1544+ color = value ;
15261545 updateColorTransform ();
15271546 return color ;
15281547 }
0 commit comments