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

Author Topic: SFML 2.0 - Repeated Animations  (Read 938 times)

0 Members and 1 Guest are viewing this topic.

Tweezy

  • Newbie
  • *
  • Posts: 43
    • View Profile
SFML 2.0 - Repeated Animations
« on: March 06, 2013, 10:20:41 pm »
Hi. I am trying to do a laser fire animation as seen in the space invaders game. I have some ideas but I really have no idea how to implement them. The idea I think I have is to have the visibility is the sprite set to off, or have it behind the tank so it looks like it isn't there, then for the sprite to follow the tank around (Left and Right). Once the space button is fired the visibility of the laser is shown, and then it shoots up towards the top of the screen. This is my second day for SFML and the only way I have tried to do the laser shoot is to use the .move but this isn't working as it only moves once and not continuously.  This is what I have at the moment:

Code: [Select]
int spriteWalkSpeed = 10;
int DownspriteWalkSpeed = 5;
int up=-spriteWalkSpeed, down=DownspriteWalkSpeed, left=-spriteWalkSpeed, right=spriteWalkSpeed;

tankSprite.setPosition(400,550);
laserSprite.setPosition(400,550);

while (App.isOpen())
{
// Process events
sf::Event Event;
while (App.pollEvent(Event))
{
if (Event.type == sf::Event::KeyPressed)
{
if (Event.key.code == sf::Keyboard::Left)
{
tankSprite.move(left,0);
}
if (Event.key.code == sf::Keyboard::Right)
{
tankSprite.move(right,0);
}
if (Event.key.code == sf::Keyboard::Space)
{
laserSprite.move(up, up);
laser.play();
}

}
           }
« Last Edit: March 06, 2013, 11:13:39 pm by Tweezy »

 

anything