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

Author Topic: Movement and origin help  (Read 2215 times)

0 Members and 1 Guest are viewing this topic.

oOhttpOo

  • Newbie
  • *
  • Posts: 40
    • View Profile
Movement and origin help
« on: May 14, 2015, 09:46:44 pm »
Hi
In a game I'm making, for one object, it has to rotate when triggered, but it's a bit complicated.  Basically I don't know how to rotate the shape from it's centre with setOrigin, because I have already used it. My code probably explains it better... Perhaps there is an easy solution to this?

 

shape1.setOrigin(-100, -375);

...
window.clear(sf::Color::Cyan);

si.setPosition(shape2.getPosition());
...
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
shape1.rotate(0.1); //need to rotate it from it's centre (x/2, y/2)
}

 
« Last Edit: May 14, 2015, 09:49:32 pm by oOhttpOo »

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: Movement and origin help
« Reply #1 on: May 14, 2015, 10:09:19 pm »
Is there any reason why you can't just set the origin to the centre, rotate it, then set the origin back to wherever you had it? If you needed to, you could store what the origin was before rotating, set it to the centre, then rotate and set it to the value you stored.

victorlevasseur

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Movement and origin help
« Reply #2 on: May 14, 2015, 10:16:30 pm »
Is this intended the negative coordinates in the setOrigin method ?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Movement and origin help
« Reply #3 on: May 14, 2015, 11:04:52 pm »
This is at least the third time that I've seen that this exact coordinate has been used for origin recently. One of those posts said they followed an online tutorial and I get the feeling that they're all following the same one (I think I followed the trail to CodingMadeEasy tutorials).

Looking up the posts, it looks like one of them was posted by the very same person and the solution was given and you said you'd fixed the problem.
Shadowmouse even gave you the code to use and the reason why.
« Last Edit: May 14, 2015, 11:06:25 pm by Hapax »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

oOhttpOo

  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: Movement and origin help
« Reply #4 on: May 15, 2015, 08:28:42 pm »
Sorry my bad, I meant to put (200, 2.5) for setOrigin. Long day  :P Have had no success with what shadowmouse has suggested though.
« Last Edit: May 15, 2015, 08:30:15 pm by oOhttpOo »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Movement and origin help
« Reply #5 on: May 15, 2015, 09:58:18 pm »
Have you read and thought about the sf::Transformable documentation? http://www.sfml-dev.org/documentation/2.0/classsf_1_1Transformable.php#details

I'm guessing you set the origin to foo, then set it back to bar and then draw. When what you want is really to set it to foo, then draw and then set it back to bar - just a guess ;-)