Computer Speeds
BlitzPlus Forums/BlitzPlus Beginners Area/Computer Speeds
| ||
I'm having issues with the speeds that my games play at... I program on an old, slow computer, and they test fine. When I play on a better computer, however, the game runs too fast and they are unplayable. Do I need to do my work on a better computer, or are there other solutions to this problem? |
| ||
First (simple) way:Graphics 640,480,0,2 mytimer = CreateTimer(60) Bild = CreateImage (160,120) SetBuffer ImageBuffer (Bild) Color 0,0,255 For a = 0 To 119 Color a*2,a*2,255 Line 0,a,159,a Next SetBuffer BackBuffer() Global move = 240 While Not KeyHit (1) Cls DrawImage Bild,move,180 move=move+1 If move >600 move = 100 WaitTimer mytimer Flip 0 Wend End This runs with 60 frames on every machine. The second way is to make your own timer with millisecs() . bye |
| ||
Use delta timing.Function DeltaTiming(period) If (MilliSecs() > (delta_timer + period)) Then delta_timer=MilliSecs() ; 'reset' the timer Return(True); End If Return(False); End Function In your main loop put something like.. Global delta_timer = MilliSecs(); While( Not KeyHit(1)) If(DeltaTiming(25)) Then UpdateControl(); UpdateGraphics(); End If Wend Just as an example but you should be able to get the idea. |
| ||
Thank you very much this information is extremely helpful... except Waittimer doesn't seem to work properly. When I use the command, it does not turn its usual yellow color and it claims that "Function waittimer not found." Not sure what that's all about. |
| ||
I dunno Sauer; I just typed it in the B+ demo & it was recognized normally. Maybe you're using an older version of Plus; have you checked for product updates? |
| ||
I'll try and see what happens... Hopefully that is all that needs resolving. Update: The product update proved effective. Thanks to everyone for all the advice. |
| ||
On a similar note, is there anyway to speed up a game for slower computers (I'm assuming there isn't)? |
| ||
Graphics 800,600,0,2 SpeedFactor#=1.0 GameTime=10 FrameTime=MilliSecs() d=1 SetBuffer BackBuffer() Repeat ;imagine this is your main loop Cls If KeyDown(203) Then d=d-1 If KeyDown(205) Then d=d+1 If d<1 Then d=1 Delay d ;ie do all your stuff you would normally do in the game... ;Example of how to apply the 'SpeedFactor' to make the game run smoothly... ;Whenever you perform an addition or subtraction multiply the amount which is added/subtracted by SpeedFactor x#=x#+1.0*SpeedFactor# Rect x,100,20,20,1 If x>GraphicsWidth() Then x=0 Text 0,0,speedfactor Text 0,15,"Delay:"+d+" (simulate a slower pc by making this larger Text 0,30," by pressing Right arrow, Left arrow decreases it) Flip False SpeedFactor#=Float(MilliSecs()-FrameTime)/Float(GameTime) FrameTime=MilliSecs() Until GameOver<>0 Or KeyDown(1) Hold down the right arrow key to see how it would look on slower computers. |