Hey, I'm currently working with timers and just found out that the "Event.TIMER" event doesn't seem to work like I thought it would.
I start a timer when the user finishes touching the screen. The event is called the number of times that I told it to. But when it finishes and the user touches the screen again, the event is called only once. That's my problem.
Full code:
test2 = gideros.class(Sprite)
function test2:init()
-- Add background
self.background = Bitmap.new(Texture.new("gfx/background.png"))
self.background:setPosition(0,80)
-- bgSprite: For the input listener
self.bgSprite = Sprite.new()
self.bgSprite:addChild(self.background)
self:addChild(self.bgSprite)
-- Init Timer
self.cooldownTimer = Timer.new(200, 10)
self.cooldownTimer:addEventListener(Event.TIMER, self.onTimerElapsed, self)
self.cooldownTimer:addEventListener(Event.TIMER_COMPLETE, self.onTimerEnd, self)
-- Release function
function release(frame, event)
self:startSubstraction()
end
-- Input listener
self.bgSprite:addEventListener(Event.MOUSE_UP, release, self.bgSprite)
end
function test2:startSubstraction()
self.percentage = 100
print("start",self.percentage)
self.cooldownTimer:start()
end
function test2:onTimerElapsed()
self.percentage = self.percentage - 10
print("elapsed",self.percentage)
end
function test2:onTimerEnd()
self.percentage = 0
print("end",self.percentage)
end |
And here is where my problem lies:
function test2:onTimerElapsed()
self.percentage = self.percentage - 10
print("elapsed",self.percentage)
end |
This method works fine the first time (it's called 10 times). But for the next ones it's called only once. What I want is for it to be called 10 times every time the user finishes touching the screen. Please help.
I'm working with ar2rs Game Template and this test2.lua is one of it's scenes
Comments
That's just a quick guess, though, witouth trying the code (and not working with timers, as I mentioned).
https://deluxepixel.com
Dislikes: John
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
What @OZApps says is true,
but if reset does not reset the internal counter in the middle (but only when the timer is done, I think it is a bug)
Here is a simple test I ran and it looks like its working correctly for me:
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps