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

Fix FlxCamera.fill() blending #3217

Merged
merged 4 commits into from
Jul 15, 2024
Merged
Changes from 2 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
26 changes: 19 additions & 7 deletions flixel/FlxCamera.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,8 @@ class FlxCamera extends FlxBasic
return;

_fxFlashColor = Color;
if (_fxFlashColor.alpha == 0)
_fxFlashColor.alpha = 0xff;
if (Duration <= 0)
Duration = 0.000001;
_fxFlashDuration = Duration;
Expand All @@ -1567,6 +1569,8 @@ class FlxCamera extends FlxBasic
return;

_fxFadeColor = Color;
if (_fxFadeColor.alpha == 0)
_fxFadeColor.alpha = 0xff;
if (Duration <= 0)
Duration = 0.000001;

Expand Down Expand Up @@ -1703,8 +1707,11 @@ class FlxCamera extends FlxBasic
if (FxAlpha == 0)
return;

var targetGraphics:Graphics = (graphics == null) ? canvas.graphics : graphics;
final targetGraphics = (graphics == null) ? canvas.graphics : graphics;

#if (openfl > "8.7.0")
targetGraphics.overrideBlendMode(null);
#end
Geokureli marked this conversation as resolved.
Show resolved Hide resolved
targetGraphics.beginFill(Color, FxAlpha);
// i'm drawing rect with these parameters to avoid light lines at the top and left of the camera,
// which could appear while cameras fading
Expand All @@ -1719,35 +1726,40 @@ class FlxCamera extends FlxBasic
@:allow(flixel.system.frontEnds.CameraFrontEnd)
function drawFX():Void
{
var fxColor:FlxColor;
var alphaComponent:Float;

// Draw the "flash" special effect onto the buffer
if (_fxFlashAlpha > 0.0)
{
alphaComponent = _fxFlashColor.alpha;
fxColor = _fxFlashColor;
alphaComponent = fxColor.alphaFloat * _fxFlashAlpha;

if (FlxG.renderBlit)
{
fill((Std.int(((alphaComponent <= 0) ? 0xff : alphaComponent) * _fxFlashAlpha) << 24) + (_fxFlashColor & 0x00ffffff));
fxColor.alphaFloat = alphaComponent;
fill(fxColor);
}
else
{
fill((_fxFlashColor & 0x00ffffff), true, ((alphaComponent <= 0) ? 0xff : alphaComponent) * _fxFlashAlpha / 255, canvas.graphics);
fill(fxColor.rgb, true, alphaComponent, canvas.graphics);
}
}

// Draw the "fade" special effect onto the buffer
if (_fxFadeAlpha > 0.0)
{
alphaComponent = _fxFadeColor.alpha;
fxColor = _fxFadeColor;
alphaComponent = fxColor.alphaFloat * _fxFadeAlpha;

if (FlxG.renderBlit)
{
fill((Std.int(((alphaComponent <= 0) ? 0xff : alphaComponent) * _fxFadeAlpha) << 24) + (_fxFadeColor & 0x00ffffff));
fxColor.alphaFloat = alphaComponent;
fill(fxColor);
}
else
{
fill((_fxFadeColor & 0x00ffffff), true, ((alphaComponent <= 0) ? 0xff : alphaComponent) * _fxFadeAlpha / 255, canvas.graphics);
fill(fxColor.rgb, true, alphaComponent, canvas.graphics);
}
}
}
Expand Down
Loading