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

Author Topic: Help in Animation.  (Read 1937 times)

0 Members and 1 Guest are viewing this topic.

mnajrg

  • Newbie
  • *
  • Posts: 26
    • View Profile
Help in Animation.
« 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.

Code: [Select]
#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();
}
}

julen26

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
    • http://julen26.blogspot.com
Help in Animation.
« Reply #1 on: December 13, 2011, 08:38:18 am »
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) function.

mnajrg

  • Newbie
  • *
  • Posts: 26
    • View Profile
Help in Animation.
« Reply #2 on: December 13, 2011, 08:45:18 am »
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!

 

anything