Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [Solved]Drawing object with origin  (Read 3169 times)

0 Members and 1 Guest are viewing this topic.

Sakurazaki

  • Newbie
  • *
  • Posts: 31
  • `お嬢様を守ります!
    • MSN Messenger - sakurazaki.setsunita@gmail.com
    • View Profile
[Solved]Drawing object with origin
« 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!
« Last Edit: June 04, 2013, 02:01:54 pm by Sakurazaki »
こんな私も変われるのならもし変われるのなら白になる

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Drawing object with origin
« Reply #1 on: June 04, 2013, 07:12:15 am »
Uh? Are you using setOrigin as a substitute for setPosition?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Drawing object with origin
« Reply #2 on: June 04, 2013, 08:04:46 am »
What do you do exactly?
Laurent Gomila - SFML developer

Sakurazaki

  • Newbie
  • *
  • Posts: 31
  • `お嬢様を守ります!
    • MSN Messenger - sakurazaki.setsunita@gmail.com
    • View Profile
Re: Drawing object with origin
« Reply #3 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?
こんな私も変われるのならもし変われるのなら白になる

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Drawing object with origin
« Reply #4 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.
Laurent Gomila - SFML developer

Sakurazaki

  • Newbie
  • *
  • Posts: 31
  • `お嬢様を守ります!
    • MSN Messenger - sakurazaki.setsunita@gmail.com
    • View Profile
Re: Drawing object with origin
« Reply #5 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 :/
こんな私も変われるのならもし変われるのなら白になる

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: Drawing object with origin
« Reply #6 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.
TGUI: C++ SFML GUI

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Drawing object with origin
« Reply #7 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.
Laurent Gomila - SFML developer

Sakurazaki

  • Newbie
  • *
  • Posts: 31
  • `お嬢様を守ります!
    • MSN Messenger - sakurazaki.setsunita@gmail.com
    • View Profile
Re: Drawing object with origin
« Reply #8 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.
こんな私も変われるのならもし変われるのなら白になる