Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I googled with best of my skills, but I cannot find any relevant answer to my problem. I'm making a game with an isometric view. I need to draw multiple sprites on the screen and before switching to next frame of the sprite, it is needed to clear the last frame of the sprite by doing a clearScreen of the window. If I do clearScreen, all of the other sprites get cleared, since the program cannot remember the last state of the screen. How can I overcome this problem?

Here is my code (I'm writing in pseudo-code, so that the solution can become implementation independent)

main.cpp
{
  //gameloop 

 Animation playerAnimation;

  while(window.isopen())
  {
    window.draw(game_map);

   if(certain_condition_is_met)
   playerAnimation.update(window)

    window.clear()
    window.display();
  }
}

   Animation.cpp

   class Animation
   {
     void update(&window) 
      {
        for(available_frames frame)
         window.draw(frame);
       //inside the above for loop ,i need to do a clearscreen to avoid overlap of 
       //frames,but this will make other sprites to be lost 
       }
   }

I'm using C++ SFML, in which there is no way to update a particular sprite without clearScreen.

share|improve this question
    
You are trying to play the entire animation in one frame? Is that necessary for your game? –  kfan Mar 17 '13 at 15:46
    
no .. that is not at all necessary –  dineshswamyp Mar 17 '13 at 15:49
    
ok. You need a variable to keep track of what frame you are on in your update function. Only draw the frame you are on each update. That way you are only drawing the sprite once per update. Then you only need to clear the screen once (per update). –  kfan Mar 17 '13 at 15:55
    
learn how loops actually work and you will see your problem –  GameDev-er Mar 18 '13 at 22:36
add comment

1 Answer

In case you needed a code example

class Animation
{
    void update()
    {
        if (condition)
        {
            advanceFrame();
        }
        frame.draw();
    }
}

Animation animation;

int main()
{
    while (window.isOpen())
    {
        window.clear();
        animation.update();
        window.display();
    }
}

The condition is most likely a timer, to update the animation every few milliseconds. This way, the animation is drawn once per update.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.