It looks like you're new here. If you want to get involved, click one of these buttons!
GCpauseBut = gideros.class(Bitmap); function GCpauseBut:init() self:addEventListener(Event.MOUSE_DOWN, self.onMouseDown, self); end function GCpauseBut:addAllListeners(sprite) local numChild = sprite:getNumChildren(); if numChild ~= 0 then for i = 1, numChild do local child = sprite:getChildAt(i) local subNumChild = child:getNumChildren(); if subNumChild ~= 0 then if child.addListeners then child:addListeners(); end self:addAllListeners(child); else if child.addListeners then child:addListeners(); end end end else if sprite.addListeners then sprite:addListeners(); end end end function GCpauseBut:removeAllListeners(sprite) local numChild = sprite:getNumChildren(); if numChild ~= 0 then for i = 1, numChild do local child = sprite:getChildAt(i) local subNumChild = child:getNumChildren(); if subNumChild ~= 0 then if child.removeListeners then child:removeListeners(); end self:removeAllListeners(child); else if child.removeListeners then child:removeListeners(); end end end else if sprite.removeListeners then sprite:removeListeners(); end end end function GCpauseBut:onMouseDown(event) if self:hitTestPoint(event.x, event.y) then if self.paused then self.paused = false; self:addAllListeners(stage); else self.paused = true; self:removeAllListeners(stage); end event:stopPropagation(); end end |
Likes: anneMurielle
Comments
I usually prefer this way:
1. I use a global variable like g_paused
2. I put
3. I use Timer.pauseAllTimers and Timer.resumeAllTimers to temporarily pause and resume all timers
4. My pause menu sprite calls event:stopPropagation() for mouse/touch events so that none of the sprites below it receives mouse/touch events.
5. I use GTween.pauseAll to temporarily pause and resume all tweens
But I used to use that for semplicity with the other sdk, where class approach wasn't as well implemented as in Gideros. Just with a local instead of a global (;
For example, with my AnimationManager class, I put a self:pause() call and a self:play() call in addListeners and removeListeners of my main player object to make it pause its animation and resume it. Helps keeping the code clean (;