Timer.lua 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 = Polycore.Timer(unpack(arg))
  21. end
  22. end
  23. function Timer:Pause(paused)
  24. local retVal = Polycore.Timer_Pause(self.__ptr, paused)
  25. end
  26. function Timer:isPaused()
  27. local retVal = Polycore.Timer_isPaused(self.__ptr)
  28. return retVal
  29. end
  30. function Timer:getTicks()
  31. local retVal = Polycore.Timer_getTicks(self.__ptr)
  32. return retVal
  33. end
  34. function Timer:Update(ticks)
  35. local retVal = Polycore.Timer_Update(self.__ptr, ticks)
  36. end
  37. function Timer:Reset()
  38. local retVal = Polycore.Timer_Reset(self.__ptr)
  39. end
  40. function Timer:hasElapsed()
  41. local retVal = Polycore.Timer_hasElapsed(self.__ptr)
  42. return retVal
  43. end
  44. function Timer:getElapsedf()
  45. local retVal = Polycore.Timer_getElapsedf(self.__ptr)
  46. return retVal
  47. end
  48. function Timer:setTimerInterval(msecs)
  49. local retVal = Polycore.Timer_setTimerInterval(self.__ptr, msecs)
  50. end
  51. function Timer:__delete()
  52. if self then Polycore.delete_Timer(self.__ptr) end
  53. end