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

Author Topic: [SOLVED]SFML 2 - Problem with Rotation and Move  (Read 1938 times)

0 Members and 1 Guest are viewing this topic.

luki0700

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • luki0700
[SOLVED]SFML 2 - Problem with Rotation and Move
« on: June 10, 2012, 06:01:28 am »
SOLVED

Hi I have one problem and I have no idea how to solve it :(

When I rotate my sprite I want to move in direction where the sprite is pointed at.
Here is the code responsible for rotating and moving the sprite.

float char_dir = main_char.getRotation();

if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) || sf::Keyboard::isKeyPressed(sf::Keyboard::W))
{
        main_char.move(cos(char_dir * M_PI / 180) * 3, sin(main_char.getRotation() * M_PI / 180) * -3);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down) || sf::Keyboard::isKeyPressed(sf::Keyboard::S))
{
        main_char.move(cos(char_dir * M_PI / 180) * -3, sin(main_char.getRotation()* M_PI / 180) * 3);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right) || sf::Keyboard::isKeyPressed(sf::Keyboard::D))
{
        main_char.rotate(2.0f);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left) || sf::Keyboard::isKeyPressed(sf::Keyboard::A))
{
        main_char.rotate(-2.0f);
}

It's not working properly.
I have no idea on how to move the character backward.
Moving forward is almost working properly. Almost :D

Also I did this because I read that it's important but it's still not working.
main_char.setOrigin(main_char_tex.getSize().x / 2, main_char_tex.getSize().y / 2);

Please help me.
Thanks.
« Last Edit: June 10, 2012, 11:31:23 pm by luki0700 »
Sorry for my english.