Scale a non-centered sprite from its center

highlanderhighlander Posts: 5Member

My game uses 2D sprites with their center property disabled for pixel scaling on different monitor resolutions.

I added a sprite scaling effect using a tween, but it scales from the sprite's top left corner since it is not centered. Is there a way to keep the sprite non-centered but to scale it from its actual center?


Tags :

Best Answers

  • MegalomaniakMegalomaniak Posts: 4,034
    Accepted Answer

    You would have to do translation in addition to scaling.

  • cyberealitycybereality Posts: 2,089
    Accepted Answer

    Yes, so you would need to do the centering yourself based on the sprite size. So you can get the size like this:

    my_sprite.texture.get_size()
    

    So now you know the unscaled size (this function is the dimensions of the texture, not the size on screen). Then based on the new scale you can do some math to move the sprite position into the place you want.

Answers

  • MegalomaniakMegalomaniak Posts: 4,034Admin
    Accepted Answer

    You would have to do translation in addition to scaling.

  • cyberealitycybereality Posts: 2,089Moderator
    Accepted Answer

    Yes, so you would need to do the centering yourself based on the sprite size. So you can get the size like this:

    my_sprite.texture.get_size()
    

    So now you know the unscaled size (this function is the dimensions of the texture, not the size on screen). Then based on the new scale you can do some math to move the sprite position into the place you want.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file