Ooops
January 26, 2021, 12:30:59 PM

Author Topic: [bb] Timescale by Streaksy [ 1+ years ago ]  (Read 458 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Timescale by Streaksy [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : Timescale
Author : Streaksy
Posted : 1+ years ago

Description : Put SyncLagScale in your main loop, and multiply every movement by Timescale#, and it'll move fluidly.  I've found this extremely useful.  It's an alternative to using frame-limitting timers.

You can even use SetTimeScale(s#) to control the speed of time.

Enjoy >D

(Code archive contribution #4)


Code :
Code: BlitzBasic
  1. Global TimeScale#,LagScale#,TimeScaleMul#=1,TimeScaleLastTime ;TIMESCALING
  2. Global TimeScaleLibPresent=1
  3.  
  4.  
  5. Function SyncLagScale()
  6. tim=MilliSecs()
  7. timepassed#=tim-TimeScaleLastTime
  8. If TimeScaleLastTime=0 Then lagscale=1 Else lagscale=(timepassed/1000)*50
  9. TimeScaleLastTime=tim
  10. timescale=lagscale*timescalemul:If timescale>6 Then timescale=6
  11. If timescale>20 Then timescale=1  ;okay thats alot... lets treat it like a delay rather than an example of framerate
  12. End Function
  13.  
  14. Function SetTimeScale(s#)
  15. timescalemul=s
  16. End Function


Comments :


Serpent(Posted 1+ years ago)

 I've been thinking for a while about doing something like this in a game - any frame rate would be supported and lag would be accounted for, which would be very useful in multiplayer games in that computers stay in sync despite one computer lagging more than the other.I was going to comment on how you should limit the scaling, but I see that you've already accounted to this.  Nicely done and useful.  Thanks for posting.


Streaksy(Posted 1+ years ago)

 Thanks again serpent =D


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal