Language

Game.curTime


Game.curTime() : float

Description

Return a float number representing the number of seconds elapsed since the start of the game.

Return

A float number representing the number of seconds elapsed.


Examples

Nicely move a sprite

This example shows you how to move a sprite using Game.curTime() and math.sin()

  1. local sprite = getEntity("sprite2move")
  2. local startposition = sprite:getPosition()
  3.  
  4. function onUpdate(elapsed)
  5.     local newy = startposition[2] + (math.sin(Game.curTime())*100)
  6.     sprite:setPosition(startposition[1], newy)
  7. end

Shoot bullets periodically

This example shows you how to shoot bullets every 1.5 seconds.

  1. local last_bullet_time = 0
  2.  
  3. function onUpdate(elapsed)
  4.     if Game.curTime() - last_bullet_time > 1.5 then
  5.         Map.createBullet(...)
  6.         last_bullet_time = Game.curTime()
  7.     end
  8. end