Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6571535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:53:42+00:00 2026-05-25T14:53:42+00:00

so I am working on a game, following a tutorial online. Currently I have

  • 0

so I am working on a game, following a tutorial online. Currently I have some FPS built into the system, and a simple animation which uses pieces of a sprite like such:

if( frameCount > 12 )
        frameCount = 0;

    //hero frames   
    SDL_Rect clip[ 13 ];

    clip[ 0 ].x = 0;
    clip[ 0 ].y = 0;
    clip[ 0 ].w = 44;
    clip[ 0 ].h = 39;

    clip[ 1 ].x = 51;
    clip[ 1 ].y = 0;
    clip[ 1 ].w = 44;
    clip[ 1 ].h = 39;

    clip[ 2 ].x = 102;
    clip[ 2 ].y = 0;
    clip[ 2 ].w = 44;
    clip[ 2 ].h = 39;
    ...
    ...
    SDL_BlitSurface( hero, &clip[ frameCount ], destination, &offset );
    frameCount++;

Now this works just fine, and each iteration of the while loop will cause it to play the next frame in the animation (This animation is part of a character class by the way).

The problem I am facing is the speed of the animation. It takes place at the current FPS of the game, which is 60. I want to be able to control the speed of the player animation separately, so I can slow it down to a reasonable speed.

Does anyone have any suggestions on how I could go about doing this?

note: There are 13 frames all together.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:53:43+00:00Added an answer on May 25, 2026 at 2:53 pm

    You have separate your refresh rate (60 fps) from your animation rate. The best solution, in my opinion, is to tie your animation rate to the real time clock. In SDL, you can do this with the SDL_Ticks() function, which you can use to measure time in millisecond resolution.

    As an example, consider this example (not working code, just a sketch):

    void init() {
        animationRate = 12;
        animationLength = 13;
        startTime = SDL_Ticks();
    }
    
    void drawSprite() {
        int frameToDraw = ((SDL_Ticks() - startTime) * animationRate / 1000) % animationLength;
        SDL_BlitSurface( hero, &clip[ frameToDraw ], destination, &offset );
    }
    

    In case it isn’t clear, the frameToDraw variable is computed by calculating how much time passed since the animation started to play. You multiply that by the animation rate and you get how many absolute frames at the animation rate have passed. You then apply the modulo operator to reduce this number to the range of your animation length and that gives you the frame you need to draw at that time.

    If your refresh rate is slower than your animation rate your sprite will skip frames to keep up with the requested animation rate. If the refresh rate is faster then the same frame will be drawn repeatedly until the time to display the next frame comes.

    I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im working on a simple html/javascript multiplication game, in which I have a multiplication
I'm working on a console game in which I have the following pieces of
I'm working on a simple multiplayer game in which 2-4 players are placed at
I am working on game engine prototype and have the following question: Right now
I'm working on my first proper Clojure program--a chess game. I have the following:
I'm currently working on a simple game that is drawn on a form by
I'm working on a game (using Ruby) and planning to have it available in
I'm working on a game engine in C++ and I have methods like setColour
I'm currently working on a couple of shaders for an iPad game and it
I have written a game (I'll give it the name Gamer) in which I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.