Skip to content

Commit

Permalink
prevent draw calls to bgsprite when transparent (#3173)
Browse files Browse the repository at this point in the history
* prevent draw calls to bgsprite when transparent

* D'oh
  • Loading branch information
Geokureli authored Jun 11, 2024
1 parent 70e064d commit 59e8ef0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
23 changes: 15 additions & 8 deletions flixel/FlxSubState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,19 @@ class FlxSubState extends FlxState
var _created:Bool = false;

/**
* @param BGColor background color for this substate
* @param bgColor background color for this substate
*/
public function new(BGColor:FlxColor = FlxColor.TRANSPARENT)
public function new(bgColor = FlxColor.TRANSPARENT)
{
super();
closeCallback = null;
openCallback = null;

if (FlxG.renderTile)
{
_bgSprite = new FlxBGSprite();
bgColor = BGColor;
}
this.bgColor = bgColor;
}

override public function draw():Void
Expand All @@ -68,9 +70,10 @@ class FlxSubState extends FlxState
camera.fill(bgColor);
}
}
else
else // FlxG.renderTile
{
_bgSprite.draw();
if (_bgSprite != null && _bgSprite.visible)
_bgSprite.draw();
}

// Now draw all children
Expand Down Expand Up @@ -102,11 +105,15 @@ class FlxSubState extends FlxState
}

@:noCompletion
override function set_bgColor(Value:FlxColor):FlxColor
override function set_bgColor(value:FlxColor):FlxColor
{
if (FlxG.renderTile && _bgSprite != null)
_bgSprite.pixels.setPixel32(0, 0, Value);
{
_bgSprite.alpha = value.alphaFloat;
_bgSprite.visible = _bgSprite.alpha > 0;
_bgSprite.color = value.rgb;
}

return _bgColor = Value;
return _bgColor = value;
}
}
1 change: 1 addition & 0 deletions flixel/system/FlxBGSprite.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class FlxBGSprite extends FlxSprite
public function new()
{
super();
// TODO: Use unique:false, now that we're not editing the pixels
makeGraphic(1, 1, FlxColor.WHITE, true, FlxG.bitmap.getUniqueKey("bg_graphic_"));
scrollFactor.set();
}
Expand Down

0 comments on commit 59e8ef0

Please sign in to comment.