October 19, 2021, 10:59:31

Author Topic: [bb] Window/Canvas frame-timing setup by cyberseth [ 1+ years ago ]  (Read 738 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Window/Canvas frame-timing setup
Author : cyberseth
Posted : 1+ years ago

Description : This app shows how to set up a Windowed game in Blitz+ with accurate frame-timing.

-- Code was overly complicated so I took out the menus --


Code :
Code: BlitzBasic
  1. Global FPS# = 60, GameTimer
  2. Global deskw=ClientWidth(Desktop()), deskh=ClientHeight(Desktop())
  3. Global gwidth# = 640, gheight# = 480 ;graphicswidth,height
  4. Global win, can
  5.  
  6. winw = 640
  7. winh = 480
  8. win = CreateWindow("Resized to gwidth,gheight",deskw/2-gwidth/2,deskh/2-gheight/2,gwidth,gheight,0,15+32)
  9.  
  10. ; Create drawing canvas
  11. can = CreateCanvas(0,0,ClientWidth(win),ClientHeight(win),win)
  12. SetGadgetLayout can,1,1,1,1 ;resizable with window
  13.  
  14.  
  15. GameTimer = MilliSecs()
  16. AutoSuspend 1
  17.  
  18. Repeat
  19.         ; Window events
  20.     Select WaitEvent(1)
  21.     Case $803  ; app close
  22.         End
  23.     End Select
  24.        
  25.         ; Timing
  26.         intv = 1000/FPS
  27.         loop = (MilliSecs()-gametimer)/intv
  28.         For k=1 To loop
  29.                 gametimer=gametimer+intv
  30.                 UpdateGame()
  31.         Next
  32.     DrawGame()
  33. Forever
  34.  
  35. Function UpdateGame()
  36.     If KeyHit(1) Then End
  37. End Function
  38.  
  39. Function DrawGame()
  40.     SetBuffer CanvasBuffer(can)
  41.     Cls
  42.  
  43.     FlipCanvas can
  44.  
  45. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal