Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Delay the application — Gideros Forum

Delay the application

misterhupmisterhup Member
edited October 2015 in General questions
Is there a way to pause the execution of an application for a specified amount of time? (other than using timers)
For example:
--code
pause the code 3 seconds
--after 3 seconds continue with the rest of the code

Comments

  • piepie Member
    enterframe event and application:frameCount() or a difference between two os.timer values - I think that also Timer.delayedCall is a good option if you're not afraid of timers :)

    Likes: misterhup

    +1 -1 (+1 / -0 )Share on Facebook
  • totebototebo Member
    edited October 2015 Accepted Answer
    The safest way of doing this is using one central onEnterFrame event that all classes subscribe to. You can then remove this one listener to pause everything in the game, then add it back to resume.

    In my case I usually have a GameLoop class that other classes listen to:
    GameLoop = gideros.class(Sprite)
     
    function GameLoop:init()
     
    	self.sprite = Sprite.new()
    	self.is_running = false
     
    end
     
    function GameLoop:start()
     
    	self.sprite:addEventListener( Event.ENTER_FRAME, self.onEnterFrame, self )
    	self.is_running = true
     
    end
     
     
     
    function GameLoop:stop()
     
    	self.sprite:removeEventListener( Event.ENTER_FRAME, self.onEnterFrame, self )
    	self.is_running = false
     
    end
     
     
     
    function GameLoop:onEnterFrame( e )
     
    	self:dispatchEvent( Event.new("UPDATE") )
    	self.frame_counter = 0
     
    end
     
     
    function GameLoop:isRunning()
     
    	return self.is_running
     
    end

    Likes: misterhup

    My Gideros games: www.totebo.com
    +1 -1 (+1 / -0 )Share on Facebook
  • ps. I'm terrified of timers. :)
    My Gideros games: www.totebo.com
  • I use Timer.pauseAll() for timers and GTween.pauseAll = true for tweens in my pause menu (as well as using a central onEnterFrame event like @totebo suggested.) Both of these, however, gave me some headaches and took a bit of rewriting and reorganizing of my code. Figuring out when to pause and resume these so they don't affect other things in the code can be tricky, but they are still useful in certain cases.

    Likes: misterhup

    +1 -1 (+1 / -0 )Share on Facebook
  • ps. I'm not afraid of timers :P
  • You could make such function, but it is not suggested, as it halts all interface, usually you need to pause only some portion of your game, like box2d physics, etc, which can be achieved through mentioned methods.

    But if you want the busy wait method, you could try this:
    http://lua-users.org/wiki/SleepFunction

    Likes: misterhup

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.