| frames_per_second (optional) - target presentation rate from 1 to 1000; 0 disables the limit (default) |
|
Caps how many frames per second your game presents. The limit applies deadline-based pacing to Flip: each frame waits until its slot rather than presenting as fast as possible. Use it to hold a prototype at a steady update rate without writing timing code, to stop menus and pause screens burning GPU for nothing, or to cap power and heat on laptops. It combines fine with VSync: whichever constraint is slower wins, so a 30 FPS limit holds on a 60 Hz display. Values above 1000 are clamped, and 0 removes the limit again. For the full story, see the image-quality guide. See also: VSync, RenderScale, Flip. |
; FrameLimit Example
; ------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
camera=CreateCamera()
PositionEntity camera,0,2,-7
RotateEntity camera,10,0,0
light=CreateLight()
RotateEntity light,45,45,0
; A windmill that turns a fixed amount per frame, so a lower
; frame limit visibly slows its spin
mill=CreatePivot()
PositionEntity mill,0,2,2
For i=0 To 3
blade=CreateCube(mill)
ScaleEntity blade,2.5,0.2,0.1
RotateEntity blade,0,0,i*45
EntityColor blade,230,120+i*30,60
Next
; Turn VSync off so the frame limit alone controls pacing
VSync False
limit=60
frames=0
fps=0
timer=MilliSecs()
While Not KeyDown(1)
; Keys 1-4 select the frame cap
If KeyHit(2) Then limit=30
If KeyHit(3) Then limit=60
If KeyHit(4) Then limit=120
If KeyHit(5) Then limit=0
; Cap the presentation rate (0 disables the limit)
FrameLimit limit
; Count real frames per second
frames=frames+1
If MilliSecs()-timer>=1000 Then
fps=frames
frames=0
timer=MilliSecs()
EndIf
TurnEntity mill,0,0,2
; Arrow keys move the camera
If KeyDown(200) Then MoveEntity camera,0,0,0.1
If KeyDown(208) Then MoveEntity camera,0,0,-0.1
If KeyDown(203) Then TurnEntity camera,0,1,0
If KeyDown(205) Then TurnEntity camera,0,-1,0
RenderWorld
Text 0,0,"1: 30 fps 2: 60 fps 3: 120 fps 4: uncapped Arrows: camera Esc: exit"
If limit=0
Text 0,20,"FrameLimit 0 (uncapped)"
Else
Text 0,20,"FrameLimit "+limit
EndIf
Text 0,40,"Measured: "+fps+" fps - the mill turns per frame, so the cap sets its speed"
Flip
Wend
End