SFML community forums
Help => Graphics => Topic started by: mnajrg on December 13, 2011, 04:21:11 am
-
I got a problem when I try to press the keyboard key A.
My animation stops when I hold down the Keyboard key A.
#include "SFML/Graphics.hpp"
#include "SFML/System.hpp"
#include "AniSprite.h"
int main()
{
sf::RenderWindow App(sf::VideoMode(640, 420,32), "Test");
sf::Image Image;
if (!Image.LoadFromFile("untitled1.bmp"))
return 1;
Image.CreateMaskFromColor(sf::Color::Black);
sf::Texture Texture;
Texture.LoadFromImage(Image);
AniSprite Sprite(Texture,93,96);
Sprite.SetLoopSpeed(0.007); //60 fps
while(App.IsOpened())
{
sf::Event Event;
while (App.PollEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::A))
Sprite.Play();
else if ((Event.Type == sf::Event::KeyReleased) && (Event.Key.Code == sf::Keyboard::A))
Sprite.Stop();
}
App.Clear();
Sprite.Update();
App.Draw(Sprite);
App.Display();
}
}
-
If you hold down de key, i'll be generating KeyPressed events and calling Sprite.Play() function every time. So you can disable key repeat with EnableKeyRepeat(bool) (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Window.php#a649576968dca1f5d8253d85a7fffd47b) function.
-
Thank you very much!
It solves my problem!
More power to SFML!
I think your Blog teaches many things about game programming
Ill visit it if I had much time!