Public Group

# FPS independant movement question

This topic is 5474 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey everyone, I'm trying to produce FPS independant movement, Can anyone tell me if this is good?
[source lang=cpp]
bool running=true;
float time2, time, deltatime;
while (running==true;)
{
time2=SDL_GetTicks();
deltatime=(time2-time) * 0.1;
time=time2;

//Game Logic, get events etc..
//Eg  xposition += spritespeed * deltatime

SDL_Delay(1);
}
[\source]


##### Share on other sites
You are using an uninitialized variable in the first iteration (time). What does the 0.1 signify? A comment is needed there me thinks.

##### Share on other sites
Quote:
 Original post by elementaryYou are using an uninitialized variable in the first iteration (time). What does the 0.1 signify? A comment is needed there me thinks.

its a snippit, uninitialized is irrelivant. This is a snippit I found out on the inter-web. I have no idea how FPS independant is supposed to work and after a few days of reading i'm at my wit's end. Most examples dont really explain how things are supposed to work and thats frustrating :S

~my~ understanding of FPS-I movement and delta time is that if the loop goes to fast, sleep, otherwise do stuff. Movement would be a speed * the delta time. But I can't find anywere that really explains it to me.

help! :s

##### Share on other sites
What you have to do is generate a frame per amount of time.

Process a frame every one 60th of a second for instance, giving you a max fps of 60 frames per second.

What you need to do is, store the current time in say variable 'currenttime', and store the time at wich you want to process a frame at variable say 'frametime'. Now set 'frametime' inicially as 'currenttime' plus one 60th of a second.

Now in the game loop, you update 'currenttime' at every pass of the cicle, and when 'currenttime' is bigger or equal to 'frametime' that means one 60th of a second has passed and you should process a frame. You increase another 60th of a second to 'frametime', and keep running the cicle until 'currenttime' is equal or bigger then 'time' again.

##### Share on other sites
simple....

float cTime,pTime; /* ctime Is the current time, pTime is the previous time*/
int framerate = 60; /* frames per a second*/

while(1)
{
cTime = getTickCount() * 0.001f; // Need to convert getTickCount
if( (cTime - pTime) > (1.0/framerate))
{

/* if the current time, minus the last time the pTime variable was update, is more then 1 / frame rate then update the pTime to the cTime and do your gameplay stuff */

pTime = cTime;
/* This is where you put all your game play stuff */

/* Not past here though. */
}

}

and does anyone know the bbcode to put that stuff in a lil box?

##### Share on other sites
ah ha.

I found my answer. If anyone else finds this thread go here

http://www.gamedev.net/community/forums/topic.asp?topic_id=220793

##### Share on other sites
Quote:
 Original post by melkor_98and does anyone know the bbcode to put that stuff in a lil box?

try the  tagsThermo 
 0 
 Share this post Link to post Share on other sites 
 
 
 Panopticon    122 Panopticon Member 122 Posted September 26, 2004 Quote:Original post by melkor_98simple....[code lang=cpp]float cTime,pTime; /* ctime Is the current time, pTime is the previous time*/int framerate = 60; /* frames per a second*/while(1){cTime = getTickCount() * 0.001f; // Need to convert getTickCountif( (cTime - pTime) > (1.0/framerate)){ /* if the current time, minus the last time the pTime variable was update, is more then 1 / frame rate then update the pTime to the cTime and do your gameplay stuff */ pTime = cTime; /* This is where you put all your game play stuff */ /* Not past here though. */}}hmm ok can you give an explination of whats going on? mabe its just a long day but my head is mush.also, what is the resolution of gettickcount? can I substitute SDL_GetTicks()? 0 Share this post Link to post Share on other sites Panopticon    122 Panopticon Member 122 Posted September 27, 2004 Hey folks, for the most part i believe i have figured out what i need. Its pieced together from mostly snippets and examples i could find.Using cone3d i even show FPS using his font.h (thats lesson4 in the tuts) If you guys feel up to it, can you run my little test app and report the fps it shows and your brief system specs? It just shows a blue rectangle floating back and forth. 800x600x16 fullscreen, double buffered, hwsurfaceThanks !!!! :Dp.s. Its amazing how much better one feels after accomplishing something!Test App[Edited by - Panopticon on September 27, 2004 12:24:03 AM] 0 Share this post Link to post Share on other sites eFoDay    300 eFoDay Member 300 Posted September 27, 2004 worst fps: 69avg fps: 85best fps: 86p4 1.8ghz 256mb ramati radeon 8500 64mb agp 4x 0 Share this post Link to post Share on other sites 
 Prev 1 2 Next Page 1 of 2   Sign in to follow this   Followers 0 
 Go To Topic Listing Forum 
 googletag.cmd.push(function() { googletag.display('div-gpt-ad-1555502746360-0'); }); Advertisement 
 Game Developer Survey We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a $15 incentive for your time and insights. Click here to start! Take me to the survey!$(document).ready(function(e) { window.survey_id = (new Date().getUTCMilliseconds().toString() + new Date().getTime().toString()).toString(); $('.surveylink').each(function(){$(this).attr("href", "http://selfserve.decipherinc.com/survey/selfserve/5c2/190900?list=2&ID="+window.survey_id); }); }); googletag.cmd.push(function() { googletag.display('div-gpt-ad-1555502640120-0'); }); Advertisement Popular Tags 2D 3D Advice C# C++ Character Concept Console Design DX11 DX12 Environments Feedback GameMaker Gameplay Graphics Javascript Mobile OpenGL Optimization PC Unity Unreal Vegetation Popular Now 12 How to make a top down 2D ball rolling By lifesuxtrStarted Yesterday at 09:05 AM 10 jump code By phil67rpgStarted Saturday at 04:33 PM 9 OpenGL Change Orientation of 3D coordinate system By tamlamStarted Friday at 02:27 AM 15 I don't understand how people apply LOD to an FFT By CelticSirStarted Wednesday at 09:19 PM 22 OpenGL 4.2 LookAt matrix only works with -z value for eye position By DBisarStarted Tuesday at 12:04 PM googletag.cmd.push(function() { googletag.display('div-gpt-ad-1555502515948-0'); }); Advertisement GameDev.net GameDev.net Articles GameDev.net Event Coverage GameDev.net Forums GameDev.net Blogs GameDev.net Gallery GameDev.net News GameDev.net Projects GDNet Chat All Activity Search In Everywhere This Forum This Topic More options... Find results that contain... All of my search term words Any of my search term words Find results in... Content titles and body Content titles only Home Groups For Beginners Forum FPS independant movement question 
 
 
 × Existing user? Sign In Sign Up Browse Back Articles & Tutorials Back All Categories Audio Business Game Design Industry Programming Visual Arts Columns Back GameDev Unboxed Event Coverage Back All Events Game Developers Conference Power Up Digital Games Conference GameDev.Market Links News Podcasts Back All Podcasts Game Dev Loadout Archive Community Back Beginners Back Beginners Group Beginners Forum Beginners Resources Blogs Calendar Chat Forums Back All Forums Audio Business Game Design Programming Visual Arts Community GameDev Challenges Affiliates Topical Workshops Gallery Groups Back For Beginners GameDev Challenges All Groups Projects Back All Projects Games Game Assets Game Mods Developer Tools Store Forums Back All Forums For Beginners Audio Back Music and Sound FX Games Career Development Business Back Games Career Development Production and Management Games Business and Law Game Design Back Game Design and Theory Writing for Games Programming Back Artificial Intelligence Engines and Middleware General and Gameplay Programming Graphics and GPU Programming Math and Physics Networking and Multiplayer Visual Arts Back 2D and 3D Art Critique and Feedback Community Back GameDev Challenges GDNet Lounge GDNet Comments, Suggestions, and Ideas Coding Horrors Your Announcements Hobby Project Classifieds Indie Showcase Affiliates Back NeHe Productions AngelCode Topical Workshops Careers Back Contractors Hobby Projects Game Jobs Back Browse on GameDev.Jobs Post a Job Members Back Subscriptions Chat Guidelines Leaderboard Online Users Awards Search Back All Activity My Activity Streams Back Latest Topics Featured Blogs Search Important Information By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.   I accept GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry. Sign me up! $(document).ready(function() { setInterval(function() { window.googletag.pubads().refresh(); }, 100000); }); googletag.cmd.push(function() { googletag.display('div-gpt-ad-1555502884201-0'); });$(document).ready(function() { if (ipsSettings.memberID > 0) { ga('send','event','User','Member'); ga('send',{ hitType: 'event', eventCategory: 'User', eventAction: 'Member', eventLabel: ipsSettings.memberID.toString() }); } else { ga('send','event','User','Guest'); } });