Timer.lua 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. require "Polycode/EventDispatcher"
  2. class "Timer" (EventDispatcher)
  3. Timer.EVENT_TRIGGER = 0
  4. function Timer:Timer(...)
  5. local arg = {...}
  6. if type(arg[1]) == "table" and count(arg) == 1 then
  7. if ""..arg[1].__classname == "EventDispatcher" then
  8. self.__ptr = arg[1].__ptr
  9. return
  10. end
  11. end
  12. for k,v in pairs(arg) do
  13. if type(v) == "table" then
  14. if v.__ptr ~= nil then
  15. arg[k] = v.__ptr
  16. end
  17. end
  18. end
  19. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  20. self.__ptr = Polycode.Timer(unpack(arg))
  21. end
  22. end
  23. function Timer:Pause(paused)
  24. local retVal = Polycode.Timer_Pause(self.__ptr, paused)
  25. end
  26. function Timer:isPaused()
  27. local retVal = Polycode.Timer_isPaused(self.__ptr)
  28. return retVal
  29. end
  30. function Timer:getTicks()
  31. local retVal = Polycode.Timer_getTicks(self.__ptr)
  32. return retVal
  33. end
  34. function Timer:Update(ticks)
  35. local retVal = Polycode.Timer_Update(self.__ptr, ticks)
  36. end
  37. function Timer:Reset()
  38. local retVal = Polycode.Timer_Reset(self.__ptr)
  39. end
  40. function Timer:hasElapsed()
  41. local retVal = Polycode.Timer_hasElapsed(self.__ptr)
  42. return retVal
  43. end
  44. function Timer:getElapsedf()
  45. local retVal = Polycode.Timer_getElapsedf(self.__ptr)
  46. return retVal
  47. end
  48. function Timer:setTimerInterval(msecs)
  49. local retVal = Polycode.Timer_setTimerInterval(self.__ptr, msecs)
  50. end
  51. function Timer:__delete()
  52. if self then Polycode.delete_Timer(self.__ptr) end
  53. end