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

Author Topic: Sprite doesn't move!  (Read 1688 times)

0 Members and 1 Guest are viewing this topic.

TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Sprite doesn't move!
« on: January 20, 2012, 03:53:06 pm »
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
Code: [Select]

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;

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sprite doesn't move!
« Reply #1 on: January 20, 2012, 06:04:22 pm »
Try App.GetFrameTime() / 1000.f ;)
Laurent Gomila - SFML developer

TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Sprite doesn't move!
« Reply #2 on: January 20, 2012, 06:12:28 pm »
Nothing happen :(
I don't know why... i think is good like this  :?:
I've seen another error, if i try to see FPS with a program (like PlayClaw, Fraps) my sprite load a lot of text o.o
Btw first i want to fix this movement problem.
Is like test is always 0 so Speed * Test is 0.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sprite doesn't move!
« Reply #3 on: January 20, 2012, 06:13:44 pm »
test might be zero if your FPS is too high. Try to enable vertical sync, or to limit framerate.
Laurent Gomila - SFML developer

TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Sprite doesn't move!
« Reply #4 on: January 20, 2012, 06:19:31 pm »
Quote from: "Laurent"
test might be zero if your FPS is too high. Try to enable vertical sync, or to limit framerate.


I love you and i'm not gay u.u
It was a super FPS issue, infact when i started PlayClaw FPS count was near 2000 :)
Now it moves good :D

I've to open new thread for the FPS overlay problem? :)

 

anything