Guest User

Love2D fixed timestep 000

a guest
Oct 28th, 2017
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.83 KB | None | 0 0
  1. local _fps = 30
  2.  
  3. gameTime = 0
  4. simulatedTime = 0
  5. timeSlice = 1 / _fps
  6.  
  7. function love.load()
  8.  
  9. end
  10.  
  11.  
  12. function love.update(dt)
  13.   gameTime = gameTime + dt
  14.  
  15.   -- this will update "one frame too many"
  16.   -- if simulated time is at 3 * timeSlice and game time is at 3.1 * timeSlice, the game
  17.   -- will do one more update, resulting in simulatedTime == 4 * timeSlice
  18.   -- we're in the future now. We'll use interpolation to render objects between their last position
  19.   -- and they're current position, letting us render the world as it should be at this time
  20.   -- this is similar to doing an in-between animation frame between two key animation frames
  21.   while(simulatedTime < gameTime) do
  22.     simulatedTime = simulatedTime + timeSlice
  23.     -- update game world and entities
  24.   end
  25.  
  26.    
  27. end
  28.  
  29.  
  30. function love.draw()
  31.  
  32. end
Advertisement
Add Comment
Please, Sign In to add comment