-
Notifications
You must be signed in to change notification settings - Fork 467
Improve FlxSprite
color transform handling, deprecate FlxColor.to24Bit()
#3413
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
base: dev
Are you sure you want to change the base?
Conversation
In general, splitting each change into a separate PR is preferred. Multi-issue PRs tend to take much longer and are less likely to get approved, but let's see what we got here
What was the issue, previously?
Can you elaborate on this? |
@@ -1506,11 +1507,12 @@ class FlxSprite extends FlxObject | |||
@:noCompletion | |||
function set_alpha(Alpha:Float):Float |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
side note, I really hate these setters, and may remove them in the future
Edit: at least remove the clamp and updateColorTransform call
Calling
After calling Note: while testing |
I don't see any evidence that alphaOffset actually works, enough to support checking for it Edit:I also don't understand why useColorTransform is needed, in most cases |
flixel/FlxSprite.hx
Outdated
if (useColorTransform) | ||
colorTransform.setMultipliers(color.redFloat, color.greenFloat, color.blueFloat, alpha); | ||
else | ||
colorTransform.setMultipliers(1, 1, 1, 1); | ||
|
||
useColorTransform = useColorTransform || colorTransform.hasRGBAOffsets(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this checked, here, rather than in line 1043?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first we need to cache the basic transform, i.e. color and alpha, then we set colorTransform multipliers based on that, and after this we cache color offset transform.
Note: on second thought, maybe it will be better to just set color offset to 0 on updateColorTransform()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't understand a case where this will behave differently than:
useColorTransform = alpha != 1 || color.rgb != 0xffffff || colorTransform.hasRGBAOffsets();
furthermore why can't this just be:
useColorTransform = alpha != 1 || color.rgb != 0xffffff || colorTransform.hasRGBAOffsets();
colorTransform.setMultipliers(color.redFloat, color.greenFloat, color.blueFloat, alpha);
Note: on second thought, maybe it will be better to just set color offset to 0 on updateColorTransform()?
I agree, but this is could cause unintended side effects to existing projects. Also, this is called whenever alpha changes. We shouldn't clear color transform offsets whenever alpha changes
Here's a test project for that. package;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.math.FlxMath;
import flixel.text.FlxText;
class PlayState extends flixel.FlxState
{
var sprite:FlxSprite;
var alphaText:FlxText;
var alphaOffsetText:FlxText;
var alpha = 1.0;
var alphaOffset = 0.0;
override public function create()
{
super.create();
// FlxG.camera.bgColor = 0xFF999999;
sprite = new FlxSprite(60, 60).makeGraphic(200, 200);
add(sprite);
alphaText = new FlxText(60, 280, 0, "", 16);
add(alphaText);
alphaOffsetText = new FlxText(60, 320, 0, "", 16);
add(alphaOffsetText);
}
override public function update(elapsed:Float)
{
super.update(elapsed);
final mult = 3 * (FlxG.keys.pressed.SHIFT ? 10 : 1);
if (FlxG.keys.pressed.Q)
setAlpha(alpha - 0.01 * elapsed * mult);
if (FlxG.keys.pressed.E)
setAlpha(alpha + 0.01 * elapsed * mult);
if (FlxG.keys.justPressed.W)
setAlpha(1);
if (FlxG.keys.pressed.A)
setAlphaOffset(alphaOffset - 1 * elapsed * mult);
if (FlxG.keys.pressed.D)
setAlphaOffset(alphaOffset + 1 * elapsed * mult);
if (FlxG.keys.justPressed.S)
setAlphaOffset(0);
sprite.setColorTransform(
sprite.colorTransform.redMultiplier, sprite.colorTransform.greenMultiplier, sprite.colorTransform.blueMultiplier, alpha,
sprite.colorTransform.redOffset, sprite.colorTransform.greenOffset, sprite.colorTransform.blueOffset, alphaOffset
);
alphaText.text = "alpha: " + FlxMath.roundDecimal(alpha, 3);
alphaOffsetText.text = "alphaOffset: " + FlxMath.roundDecimal(alphaOffset, 3);
}
function setAlpha(value:Float)
alpha = FlxMath.bound(value, 0, 1);
function setAlphaOffset(value:Float)
alphaOffset = FlxMath.bound(value, -255, 255);
} Note: only negative
|
updateFramePixels and useFramePixels only effect renderBlit targets, btw, are you using these in a project |
useFramePixels actually works perfectly on renderTile, have no idea what you ment by that.
Yes, but now as an experiment, disabled caching is a bit concerning |
Yeah sorry, this works on renderTile, but it seems like the purpose of these is to enable blitting functionality when flixel is in renderTile mode
What I mean is, are you only using these in academic experiments, or do you have a practical use for this? I recently found out that updateFramePixels was used in getPixelAt() when it didn't need to. It was causing worse performance, and I'm wondering if it should just be avoided in renderTile, altogether |
let me know if you see any issues, here. also in 3416 you mention:
I do not see that, and I'm not sure why I would, am I missing something? |
Changes:
FlxSprite.setColorTransform()
now bypassescolor
andalpha
setters.FlxSprite.useColorTransform
now accounts for alpha offset.FlxColor.to24Bit()
is now deprecated in favor ofFlxColor.rgb
field.