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'm animating a sprite in 2D with key frames of rotation and xy-positions.

I've recently had a discussion with someone saying that when the device (happens to be an iPad using cocos2D) hits a performance bump due to whatever else the user may be doing, lag will arise and that the best way to fight it is to not use actual positions, but velocities, accelerations and torques with kinematics. His message is to evaluate the positions and rotations from these speeds at the current point in time.

I've never experienced a situation where I've heard of using kinematics to stem lag in 2D animations and am not sure of how effective it could be. Also, it seems to be overkill.

The application is not networked so it's all running on a local device. The desired effect is that the animation always plays as closely as it can to the target frame rate.

Wouldn't the technique suffer the same problems as just using the time since the last frame or a fixed time step since the kinematics would also require some time value to perform the calculation?

What techniques could you suggest to best achieve the desired effect?

EDIT 1

Thank you for your responses, they are very illuminating. I want to clarify my question before choosing an answer however, to make sure that this post really serves it's purpose.

I have a sprite of a ball, and a text file with 3 arrays worth of information (rotation,translations x, translations y) with each unit of information existing as a key frame to be stepped through (0 to 49 and back to 0 to replay it again). I have this playing by interpolating from the current key frame to the next, every n-units of time. The animation is visibly correct when compared to a video I was given of it, and it is smooth because of the interpolations between the key frames. This is the existing state of the project.

There are no physics simulated, only a static animation of a ball moving in a way an artist specifically designed.

Should I, instead of rotation in degrees and translations by positions in space, derive velocities, accelerations and torques to express this static animation as a function of time? As in, position now = foo(time now), where foo uses kinematics.

share|improve this question
2  
Your physics should be using kinematics anyways. Updating "per tick" and depending on a steady framerate is asking for trouble. Your simulation should calculate physics as a function of time like your friend said. It's not overkill, its how you're supposed to do it. –  Amplify91 May 24 '12 at 22:47
    
There seems to be some confusion in my question (so I edited it to try to help). There are no physics in this application. Simply a static 2D animation via keyframes of information. I'm asking if the keyframes should be position/angles or velocity/acceleration/torque. –  viperld002 May 28 '12 at 22:13
add comment

2 Answers

Like Amplify91 said, it's not recommended to depend on a fixed framerate, even for an offline game. It's best to keep the game logic and rendering logic separated.

The game logic updates the objects positions, statistics, and check for collisions and responds to inputs, and that is independent of the framerate because it's called at regular intervals. The rendering logic takes care of perspective, visibility and effects and ultimately renders objects on the screen, and that is framerate dependent because the longer it takes to render a scene, the lower will be the framerate.

So if you have an event that is called every frame, use some variable to hold the information how much time has passed since the last call and update every variable that has an impact on animations and rendering by that amount.

This is an exapmle of fixed and variable framerate. Sorry if the language is not what you use, but the exapmle is easy to read and shows how you can use the time passed from the last frame call (´FP.elapsed´ in the example) to update the game logic.

share|improve this answer
2  
This is required reading for everyone who wants to write a game loop: gafferongames.com/game-physics/fix-your-timestep –  knight666 May 25 '12 at 11:30
    
@knight666 Great article! Thanks! –  Mentoliptus May 25 '12 at 14:59
    
Thanks for these great resources. –  viperld002 May 28 '12 at 16:19
add comment
up vote 0 down vote accepted

So the answers given were insightful but off target. I reworded my question a bit to hopefully clarify but I didn't receive any more responses so here is what I've found through some research.

The technique is called "Animation Accumulation".

Some one talks about it here, http://forum.unity3d.com/threads/8192-Is-Animation-Accumulation-supported. The poster sounds like they have lot of experience with the subject but does not go into it or give references.

The main idea (I believe) is that instead of setting the animation, you accumulate it. Doing this, when lag occurs the animation resumes playing exactly where it left off. If you were setting the animation (as a function of time somehow), returning from lag would create several undesirable effects (such as teleporting).

Unfortunately I haven't been able to find more material on the subject.

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.