SFML community forums

Help => Graphics => Topic started by: Sakurazaki on June 04, 2013, 02:35:24 am

Title: [Solved]Drawing object with origin
Post by: Sakurazaki on June 04, 2013, 02:35:24 am
Hello,

I've got a sf::Sprite which I initialise with setOrigin instead of setPosition.

When I try to draw it to renderwindow, despite everything (origin and pos) are the correct,
the texture is drawn in top left corner (0, 0).

Is there something I'd to know when drawing sprites with setOrigin?

thanks!
Title: Re: Drawing object with origin
Post by: G. on June 04, 2013, 07:12:15 am
Uh? Are you using setOrigin as a substitute for setPosition?
Title: Re: Drawing object with origin
Post by: Laurent on June 04, 2013, 08:04:46 am
What do you do exactly?
Title: Re: Drawing object with origin
Post by: Sakurazaki on June 04, 2013, 01:02:48 pm
I've got a Sprite which on resizing move's his origin.

I want to set its center in order to don't make it move when resizing, so I set his origin to his position
and then resize it.

Am I doing it wrong?
Title: Re: Drawing object with origin
Post by: Laurent on June 04, 2013, 01:10:01 pm
If the origin is set to the point that mustn't move, you shouldn't have to change it everytime the sprite is resized.
Title: Re: Drawing object with origin
Post by: Sakurazaki on June 04, 2013, 01:12:13 pm
I don't change it. I CREATE the sprite with a position and a origin, and then resize it.

I've read the tutorial in here:
http://www.sfml-dev.org/tutorials/2.0/graphics-transform.php

But I'm sure I didn't understand how origin and scale work :/
Title: Re: Drawing object with origin
Post by: texus on June 04, 2013, 01:36:45 pm
Quote
so I set his origin to his position
Don't forget that the origin is relative to your sprite. If your image is 50x50 and you want the origin in the center of it then set it to (25, 25), even if the sprite has e.g. position (100, 100).

Is that what you were doing wrong?
If not then you should provide a small example code so that it is clear what you are doing.
Title: Re: Drawing object with origin
Post by: Laurent on June 04, 2013, 01:41:49 pm
Quote
I've got a Sprite which on resizing move's his origin.
Quote
I don't change it. I CREATE the sprite with a position and a origin, and then resize it.
This is not clear :P

The origin is the point (in local coordinates!) that never changes when you apply transformations to your sprite. So, for example, if your sprite is a character, the origin will most likely be the bottom-middle point (under its feet), so that when resized it grows up but not down. And equally on the left and right.

You should describe precisely what you do (what kind of sprite you have, where is the point that should never move, etc.) so that we can give more relevant advices.
Title: Re: Drawing object with origin
Post by: Sakurazaki on June 04, 2013, 02:01:42 pm
Quote
so I set his origin to his position
Don't forget that the origin is relative to your sprite. If your image is 50x50 and you want the origin in the center of it then set it to (25, 25), even if the sprite has e.g. position (100, 100).

Is that what you were doing wrong?
If not then you should provide a small example code so that it is clear what you are doing.

Yes, i guess thats exactly what I'm doing.

Thank you, knowing that origin is taken from the top left corner of sprite and not from the window I changed
my origin to the correct position and now works as intended.