Skip to content

Incorrect coloring of animated sprites with useFramePixels on renderTile #3414

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

Open
richTrash21 opened this issue Apr 8, 2025 · 0 comments · May be fixed by #3416
Open

Incorrect coloring of animated sprites with useFramePixels on renderTile #3414

richTrash21 opened this issue Apr 8, 2025 · 0 comments · May be fixed by #3416

Comments

@richTrash21
Copy link
Contributor

richTrash21 commented Apr 8, 2025

While testing #3413 i've encountered an issue where using useFramePixels on animated sprites would incorrectly apply color transformation. This bug affects only renderTile targets.

Here's code to reproduce this issue:

package;

import flixel.FlxSprite;
import flixel.text.FlxText;

class TestState extends flixel.FlxState
{
	var colors = [0xAA0000, 0x00AA00, 0x0000AA, 0xAAAA00, 0x00AAAA];
	var curColor = 0;

	var bugged:FlxSprite;
	var expected:FlxSprite;

	override public function create()
	{
		super.create();

		FlxG.camera.bgColor = 0xFF999999;

		add(new FlxText(50, 20, 0, "Bugged", 16));

		bugged = makeCube(30, 60);
		add(bugged);
		bugged.useFramePixels = true;

		add(new FlxText(200, 20, 0, "Expected", 16));

		expected = makeCube(180, 60);
		add(expected);

		add(new FlxText(350, 20, 0, "Graphic", 16));

		final graphic = makeCube(330, 60);
		add(graphic);

		switchColor();
		new flixel.util.FlxTimer().start(3, switchColor, 0);
	}

	override public function update(elapsed:Float)
	{
		super.update(elapsed);

		if (FlxG.keys.justPressed.Q)
			changeAlpha(-1);
		if (FlxG.keys.justPressed.E)
			changeAlpha(1);
	}

	function makeCube(x:Float, y:Float):FlxSprite
	{
		// can be just solid color sliced into frames
		final cube = new FlxSprite(x, y).loadGraphic("assets/images/cube_test.png", true, 70, 70);
		cube.setGraphicSize(120, 120);
		cube.updateHitbox();
		cube.animation.add("anim", [0, 1, 2], 8);
		cube.animation.play("anim");
		return cube;
	}

	function switchColor(?_)
	{
		final color = colors[curColor];
		bugged.color = color;
		expected.color = color;
		curColor = ++curColor % colors.length;
	}

	function changeAlpha(mult:Int)
	{
		bugged.alpha += 0.1 * mult;
		expected.alpha += 0.1 * mult;
	}
}

Running this code will result in this: applied color appear darker or as a mix of previous and current colors.

project_axyu_5QWcf0LkDa.mp4

Image

@richTrash21 richTrash21 changed the title Incorrect coloring of animated sprites with useFramePixels Incorrect coloring of animated sprites with useFramePixels on renderTile Apr 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant