I've a little tutorial code to test Move() func of a prite.
But the sprite doesn't want ot move, here my little full code:
SFML 2
int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML",sf::Style::Close | sf::Style::Titlebar);
sf::Texture HeroIMG;
sf::Sprite HeroSprite;
float Speed=400.0f;
HeroIMG.LoadFromFile("data/img/hero.jpg");
HeroSprite.SetTexture(HeroIMG);
HeroSprite.SetPosition((float)App.GetWidth()/2-(HeroSprite.GetGlobalBounds().Width/2),(float) App.GetHeight()/2-(HeroSprite.GetGlobalBounds().Height/2));
// Start game loop
while (App.IsOpen())
{
float test = App.GetFrameTime() / 1000;
// Process events
sf::Event Event;
if (App.PollEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Escape))
App.Close();
}
if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Left))
HeroSprite.Move(-Speed * test, 0);
if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Right))
HeroSprite.Move( Speed * test, 0);
if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Up))
HeroSprite.Move(0, -Speed * test);
if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Down))
HeroSprite.Move(0, Speed * test);
App.Clear();
App.Draw(HeroSprite);
// Display window contents on screen
App.Display();
}
return EXIT_SUCCESS;
}
I tried to:
- change test from float to Uint32;
- delete /1000;
- change /1000 in *1000;
- put left/right/up/down events inside App.PollEvent;