Help with fps code - please!
Blitz3D Forums/Blitz3D Programming/Help with fps code - please!
| ||
Please could someone check this timing code. It's driving me mad. It should of course be limited to 30 fps, but when I'm looking out to sea (no entiites) it rises up as high as 54 even on my dog-slow machine. On a ninja machine it can rise up to 60 fps causing my characters to speed-walk, and other silly frame dependant effects. [CODE] Const FPS=30 Global framePeriod = 1000/FPS Global frameTime = MilliSecs() - framePeriod Global frameElapsed Global frameLimit ;------------------- Function MainRedraw() ;------------------- Local frameTicks, frameTween# Local z Repeat frameElapsed = MilliSecs()-frameTime Until frameElapsed frameTicks = Int(Float(frameElapsed) / Float(framePeriod) ) frameTween# = Float(frameElapsed Mod framePeriod) / Float(framePeriod) For frameLimit = 1 To frameTicks frameTime = frameTime + framePeriod If frameLimit = frameTicks Then CaptureWorld ; PlayerFunctions(mousemode) ; CharServices() ; UpdateScene() UpdateWorld() Next RenderWorld frameTween# ; 2D Overlays VWait Flip False ; Wav_Services() ; Music_Services() End Function [/CODE] Would really appreciate some feedback on this. Thanks. |
| ||
I would use something entirely diffrentConst FPS=30 Global framePeriod = 1000/FPS Global frameTime = MilliSecs() - framePeriod Global frameElapsed Global frameLimit ;------------------- Function MainRedraw() ;------------------- Local frameTicks, frameTween# Local z ms=millisecs() while ms<frametime delay 1 ms=millisecs() wend frametime=ms+frameperiod ; PlayerFunctions(mousemode) ; CharServices() ; UpdateScene() UpdateWorld() RenderWorld ; 2D Overlays Flip ; Wav_Services() ; Music_Services() End Function Not shure if you need the Frame Tweening at all. |
| ||
I thought frame tweening was supposed to be absolutely crucial for smooth animation of moving characters? |
| ||
I am not the most wise guy around, but I think when you want to limit the game to 30 Frames then you can also use static values for Movement and Animation Speeds. If you use variable Frametimes and Movementvalues then you can also use the UpdateWorld(n) Parameter to adjust the Animation Speed. But to be honest - I never use Captureworld, Frametweening aso., so I could be totally wrong here. |
| ||
Oh...a wise guy, eh? nyuk nyuk |
| ||
I said I am not. |