MonoGame.Extended icon indicating copy to clipboard operation
MonoGame.Extended copied to clipboard

Incorrect default `Origin` value for `Sprite` class

Open AristurtleDev opened this issue 11 months ago • 5 comments

The Sprite class should have a default origin of (0, 0) to match the default SpriteBatch.Draw origin parameter being the top-left corner. Currently, in the Sprite constructor, OriginNormalized is set to (0.5, 0.5) which is causing the Origin to update to center of the sprite.

https://github.com/craftworkgames/MonoGame.Extended/blob/080f5e1f23ed25e0011c7d6471b3e37fada85c30/source/MonoGame.Extended/Graphics/Sprite.cs#L148

This should be set to the default Vector2 value or Vector2.Zero

AristurtleDev avatar Jan 10 '25 17:01 AristurtleDev

I think this "fix" from 4.0.4 actually messes up something else.

kaltinril avatar May 15 '25 06:05 kaltinril

Either the change in #969 breaks standard sprite handling, or, perhaps it breaks tile map rendering positioning?

4.0.3 https://github.com/user-attachments/assets/ed866493-c4fd-40e4-acb6-1450e611d1c2

4.0.4 https://github.com/user-attachments/assets/9c87a831-f754-4007-961c-97dc1ea50811

kaltinril avatar May 15 '25 06:05 kaltinril

Looks like before the Tile was being created in the sample with a half sprite size positive adjustment. Removing this didn't fix the issue but put the player halfway into the tile. Subtracting half instead does fix it.

It feels odd that this is nesesary. MonoGame.Extended-samples\src\Games\Platformer\EntityFactory.cs

Image

kaltinril avatar May 15 '25 06:05 kaltinril

Pong is also now broken after 4.0.4. Fixing that also.

kaltinril avatar May 15 '25 06:05 kaltinril

I worked around this change in the samples https://github.com/craftworkgames/MonoGame.Extended-samples/pull/28

kaltinril avatar May 15 '25 07:05 kaltinril

This issue has been resolved in PR #969 and is included in version 5.1.1.

The Sprite class constructor now correctly defaults the origin to Vector2.Zero (0, 0) instead of (0.5, 0.5), matching the default SpriteBatch.Draw behavior where the origin is the top-left corner.

The fix ensures that OriginNormalized is set to Vector2.Zero when the texture region doesn't specify an origin:

OriginNormalized = textureRegion.OriginNormalized ?? Vector2.Zero;

Closing as resolved.

AristurtleDev avatar Oct 21 '25 03:10 AristurtleDev

Are the samples working after you r change?

kaltinril avatar Oct 21 '25 16:10 kaltinril