Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent draw calls to bgsprite when transparent #3173

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
2 changes: 2 additions & 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 All @@ -29,6 +30,7 @@ class FlxBGSprite extends FlxSprite

_matrix.identity();
_matrix.scale(camera.viewWidth, camera.viewHeight);
_matrix.translate(camera.viewMarginLeft, camera.viewMarginTop);
camera.drawPixels(frame, _matrix, colorTransform);

#if FLX_DEBUG
Expand Down
Loading