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

Last Sprite code update for Texture2DRegion UV breaks ORIGIN #950

Closed
kaltinril opened this issue Sep 22, 2024 · 1 comment · Fixed by #951
Closed

Last Sprite code update for Texture2DRegion UV breaks ORIGIN #950

kaltinril opened this issue Sep 22, 2024 · 1 comment · Fixed by #951

Comments

@kaltinril
Copy link
Contributor

kaltinril commented Sep 22, 2024

The Origin is not being set correctly now that the updated code for OriginNormalized is using UV's.

The OriginNormalized is set to 0.5, and then the Origin ends up ALSO being set to 0.5 This is breaking tutorials and code that wants the origin to be the midway point.

I think it should be using .width and .height

It was updated in PR 897.

From:

get { return new Vector2(Origin.X / TextureRegion.Width, Origin.Y / TextureRegion.Height); }
set { Origin = new Vector2(value.X * TextureRegion.Width, value.Y * TextureRegion.Height); }

to:

        get
        {
            float normalizedX = (Origin.X - TextureRegion.LeftUV) / (TextureRegion.RightUV - TextureRegion.LeftUV);
            float normalizedY = (Origin.Y - TextureRegion.TopUV) / (TextureRegion.BottomUV - TextureRegion.TopUV);
            return new Vector2(normalizedX, normalizedY);
        }
        set
        {
            float actualX = value.X * (TextureRegion.RightUV - TextureRegion.LeftUV) + TextureRegion.LeftUV;
            float actualY = value.Y * (TextureRegion.BottomUV - TextureRegion.TopUV) + TextureRegion.TopUV;
            Origin = new Vector2(actualX, actualY);
        }

In this commit (Hard to find because the file moved and updated in the same PR)

#897

image

Image to help understand the Texture2DRegion attributes.
https://github.com/craftworkgames/MonoGame.Extended/blob/develop/source/MonoGame.Extended/Graphics/Texture2DRegion.cs

image

@kaltinril
Copy link
Contributor Author

The more I look at the code, the more I think it just needs to get reverted, I don't see the point of using the UV's here.

The Origin is supposed to be relative to the Rectangle Bounds. Thus, the original code was accurate at saving the Origin, and producing the OriginNormalized value, am I missing something?

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