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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - luki0700

Pages: [1]
1
Graphics / [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.

Pages: [1]