Language

onUpdate


onUpdate(float elapsed)

Description

onUpdate() is a callback function called at each frame of the game.

Parameters

elapsed
A float reprenting the number of seconds elapsed between this game frame and the last one.

Examples

Move an object in an independant-framerate way.

  1. local myentity = getEntity("myEntity")
  2. local speed = 75 -- 75px per seconds
  3.  
  4. function onUpdate(elapsed)
  5.     local new_x = myentity:getPosition()[1] + (speed*elapsed)
  6.     myentity:setPosition(new_x, 200)
  7. end