Skip to content

Conversation

Geokureli
Copy link
Member

@Geokureli Geokureli commented Sep 12, 2025

Closes #3471

Fixes a bug introduced in #3371, discovered and fixed by @richTrash21 in #3472

right and top were accidentally flipped, not sure How I missed this.

I should also consider adding unit tests - Done

snippet reproing issue:

package states;

import flixel.FlxG;
import flixel.FlxStrip;
import flixel.util.FlxColor;
import openfl.display.BitmapData;
import openfl.geom.Rectangle;

class UVRectTestState3471 extends flixel.FlxState
{
	override function create()
	{
		super.create();
		
		FlxG.camera.bgColor = flixel.util.FlxColor.GRAY;
		
		// Create a bitmap of red with one frame that is white, with a black outline and green inset
		final bitmap = new BitmapData(450, 250, true);
		bitmap.fillRect(bitmap.rect, FlxColor.RED);
		bitmap.fillRect(new Rectangle(200, 100, 50, 50), FlxColor.BLACK);
		bitmap.fillRect(new Rectangle(205, 105, 40, 40), FlxColor.WHITE);
		bitmap.fillRect(new Rectangle(220, 120, 10, 10), FlxColor.GREEN);
		
		final strip = new FlxStrip();
		add(strip);
		
		strip.frames = flixel.graphics.frames.FlxAtlasFrames.fromSparrow(bitmap, xmlData);
		final frame = strip.frames.getByName("frame");
		strip.animation.frameIndex = 0;
		
		// Add Indices
		strip.indices.push(0); // A
		strip.indices.push(1); // B
		strip.indices.push(2); // C

		strip.indices.push(0); // A
		strip.indices.push(3); // D
		strip.indices.push(2); // C
		
		// Add Vertices
		
		// top left (A)
		strip.vertices.push(0);
		strip.vertices.push(0);
		// top right (B)
		strip.vertices.push(frame.frame.width);
		strip.vertices.push(0);
		// bottom right (C)
		strip.vertices.push(frame.frame.width);
		strip.vertices.push(frame.frame.height);
		// bottom left (D)
		strip.vertices.push(0);
		strip.vertices.push(frame.frame.height);
		
		// Add UV
		
		// top left (A)
		strip.uvtData.push(frame.uv.left);
		strip.uvtData.push(frame.uv.top);
		// top right (B)
		strip.uvtData.push(frame.uv.right);
		strip.uvtData.push(frame.uv.top);
		// bottom right (C)
		strip.uvtData.push(frame.uv.right);
		strip.uvtData.push(frame.uv.bottom);
		// bottom left (D)
		strip.uvtData.push(frame.uv.left);
		strip.uvtData.push(frame.uv.bottom);
		
		strip.screenCenter();
	}
}

private final xmlData = 
'<TextureAtlas imagePath="bold.png">
	<SubTexture name="frame" x="200" y="100" width="50" height="50" />
</TextureAtlas>';

Before:
Screenshot 2025-09-12 at 4 45 44 PM

After/Expected:
Screenshot 2025-09-12 at 4 45 21 PM

@Geokureli Geokureli added this to the 6.1.1 milestone Sep 12, 2025
@Geokureli Geokureli changed the title fix typos in FlxUVRect Fix typos in FlxUVRect Sep 12, 2025
@Geokureli Geokureli merged commit 9232795 into HaxeFlixel:dev Sep 12, 2025
10 checks passed
@Geokureli Geokureli deleted the uv-fix branch September 14, 2025 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FlxFrame: Incorrect UV values
1 participant