Can't get smooth sprite movement @ <50fps
BlitzMax Forums/BlitzMax Programming/Can't get smooth sprite movement @ <50fps
| ||
Hi, I can't seem to get smooth sprite movement at lower FPS rates. Throwing delta timing aside (which I thought was the problem) and using what should be steady(ish) delays, I'm still getting blurred sprites between 30 - 50fps Surely this shouldn't be happening at anything above 30fps? Try this and also try changing the delay method between delay, a loop and a timer. When using the Delay & loop method, use '1' and '2' to adjust the delay. Also try without Cls, same happens. Am I doing something wrong? Cheers Tom Strict Graphics 800,600,32,60 '60hz AutoMidHandle True SetMaskColor(255,0,255) Global blob:TImage = LoadImage("C:\blitzmax\samples\simonh\fireworks\spark.png") Global fps:fpsCounter = New fpsCounter Global pause:Int = 0 Global bx:Int = 0 Global timer:Int = CreateTimer(40) While Not KeyHit(KEY_ESCAPE) Local b:Int,i:Int 'throw in a delay Delay pause 'WaitTimer(timer) 'an alternative to Delay 'For i=1 To pause * 1000000 ' b=i*i 'Next If KeyHit(KEY_1) pause:-1 If KeyHit(KEY_2) pause:+1 If pause<0 pause=0 Cls DrawImage blob,bx,100 bx:+10 If bx>799 Then bx = 0 fps.update() DrawText("use '1' and '2' to alter pause: "+pause,0,0) DrawText("FPS: "+fps.currentFPS,0,40) Flip FlushMem Wend End Type fpsCounter Field currentFPS:Int Field oldMS:Int Field counter:Int Method Update() counter:+1 If (MilliSecs() - oldMS) > 1000 oldMS = MilliSecs() currentFPS = counter counter = 0 End If End Method End Type |
| ||
This looks to be simply the effect of using `Flip` which automatically synchronizes your program to update every 30 or 60 fps, regardless of whatever else delays you might be using. Flip has a framerate timing thing built in, unless you call: SetSwapInterval(0) (I think) ... which disables it (call it once at the top). You will be seeing the streakyness/blurriness of sprites moving (the 25-30fps effect) at framerates from 30 to 59 because the Flip command is downsizing the framerate to 30fps all the time. You might be thinking you're running at 30-59 fps but it's really either going to lock on to 30 or 60 (or multiples of that, or 15 or 8 or 4 or 2 etc). |
| ||
You don't want swapinterval when you have a dx program. You want to set your refresh rate to -1, which has the same effect as flip 0. |
| ||
[try this]Strict Local D3D7 = D3D7Max2DDriver() Local OpenGL = GLMax2DDriver() SetGraphicsDriver(OpenGL) Graphics 800,600,32,60 '60hz AutoMidHandle True SetMaskColor(255,0,255) Global blob:TImage = LoadImage("C:\Program Files\blitzmax\samples\simonh\fireworks\spark.png") Global fps:fpsCounter = New fpsCounter Global pause:Int = 0 Global bx:Int = 0 Global timer:Int = CreateTimer(40) While Not KeyHit(KEY_ESCAPE) Local b:Int,i:Int 'throw in a delay Delay pause 'WaitTimer(timer) 'an alternative to Delay 'For i=1 To pause * 1000000 ' b=i*i 'Next If KeyHit(KEY_1) pause:-1 If KeyHit(KEY_2) pause:+1 If pause<0 pause=0 Cls DrawImage blob,bx,100 bx:+10 If bx>799 Then bx = 0 fps.update() DrawText("use '1' and '2' to alter pause: "+pause,0,0) DrawText("FPS: "+fps.currentFPS,0,40) Flip FlushMem Wend End Type fpsCounter Field currentFPS:Int Field oldMS:Int Field counter:Int Method Update() counter:+1 If (MilliSecs() - oldMS) > 1000 oldMS = MilliSecs() currentFPS = counter counter = 0 End If End Method End Type |
| ||
I'm beginning to think it's a driver problem here or something. Shagwana had some delta test code, and if I slow that down (using his coded method) to about 50fps I'm seeing blurred edges on sprites in the direction they're moving. I'll check with him and post it to see if you guys are seeing it. I'm on nvidia 71.89s at the moment, the latest ones give a 'cannot create D3D' type error trying to boot up my kids lego game! Tom |