SFML community forums

Help => General => Topic started by: aanthonyz on May 14, 2014, 06:39:44 am

Title: Sprite Origin
Post by: aanthonyz on May 14, 2014, 06:39:44 am
Hello, so for textures and and sprites, the origin is the top left, 0,0. If I want to change this to the bottoms left, should I just make it 0,(whatever the size of the image is), when I use the function setOrigin, or does that function do something completely different?
Title: Re: Sprite Origin
Post by: G. on May 14, 2014, 06:51:45 am
Yes, set it to 0,(whatever the size of your sprite is) with setOrigin to set the origin of your sprite to its bottom left corner.
Title: Re: Sprite Origin
Post by: Voroz on May 16, 2014, 12:52:40 pm
Yes, set it to 0,(whatever the size of your sprite is) with setOrigin to set the origin of your sprite to its bottom left corner.
Isn't he supposed to set it to the sprites height?
Sprite.setOrigin(0, Sprite.getTextureRect().height);
Title: Re: Sprite Origin
Post by: select_this on May 16, 2014, 12:56:01 pm
Yes, set it to 0,(whatever the size of your sprite is) with setOrigin to set the origin of your sprite to its bottom left corner.
Isn't he supposed to set it to the sprites height?
Sprite.setOrigin(0, Sprite.getTextureRect().height);

I'm sure that's what he meant by 'size'  :)
Title: Re: Sprite Origin
Post by: Voroz on May 16, 2014, 12:58:44 pm
Yes, set it to 0,(whatever the size of your sprite is) with setOrigin to set the origin of your sprite to its bottom left corner.
Isn't he supposed to set it to the sprites height?
Sprite.setOrigin(0, Sprite.getTextureRect().height);

I'm sure that's what he meant by 'size'  :)
Sorry i missunderstood then. I didn't think that paranthesis "(whatever the size of your sprite is)" was supposed to be the y and the 0 the x. I thought he meant to set it all to 0 no matter the size of the sprite ^^. nevermind :)
Title: Re: Sprite Origin
Post by: Doodlemeat on May 16, 2014, 07:05:28 pm
use getGlobalBounds().height/width, then you will get the sprite dimensions. If you do getTextureRect(), you will get the texture dimensions.
Title: Re: Sprite Origin
Post by: G. on May 16, 2014, 07:12:26 pm
No. getTextureRect is correct. It gives the dimensions of the textureRect without any transformation.
getGlobalBounds give the dimensions of the bounding box of the sprite with transformations applied (scale rotations etc.).
setOrigin ignores all transformations.

(And yes, that's what I meant by "size", I used the same formulation as he did :p )