Make a method pause???

Member
Posts: 22
Joined: 2007.05
Post: #1
OK. First of all I have committed the cardinal sin.... no sleep and still trying to work on my program.

Second: I have looked all over the place and can not figure out how to make my program pause for X seconds. Basically, I have a loop that draws images to the screen and I want to slow it down. My apologies if this is a ridiculous question.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Code:
man 3 sleep

You very seldom actually want to do this...
Quote this message in a reply
Moderator
Posts: 1,562
Joined: 2003.10
Post: #3
More appropriately, see NSTimer etc.
Quote this message in a reply
Member
Posts: 22
Joined: 2007.05
Post: #4
Can anyone point me at an example of using NSTimer to just pause a method?
Quote this message in a reply
Moderator
Posts: 1,562
Joined: 2003.10
Post: #5
Well, that's really not the way to use NSTimer. The idea would be to create and schedule an NSTimer to fire at some time in the future, then return to the main event loop. Once the timer fires, it can call a method that starts where the method that invoked it left off.

You might have to rearrange your code a bit for this to work, but it'll likely clean up its design tremendously, not to mention playing much more nicely with the system in general. If you can organize your program logically into small tasks which can be triggered by a timer or a user event, you'll really be a lot better off than writing some sort of hack that pauses a method halfway through. Remember, if you don't return to the main event loop, your application can't process any events, and you'll start beachballing after a few seconds.
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #6
...or you could just stop all animation and stuff from animating. This will preserve your program's sense of time (i.e. for calculating time-base animation), and preserve your user input (i.e. so they can quit and stuff.)

Another thing you could do is just completely convert your updating to be multiplied by a speed coeficient. Then just set it to zero. But, this also allows really cool slomo/speed-up effects!

It's not magic, it's Ruby.
Quote this message in a reply
Post Reply