|Mar 1, 2009, 08:16 PM||#1|
Thread usage -- how many and which one should be on main thread
I have a game with which mostly consists of the following:
a)Timer every second for clock
b)Timer ever 0.02 for animating many objects (this is always running)
c)User interaction with objects
I'm new to using multiple threads so I'm wondering what is suggested usage here. I currently have everything on the main thread except timer 'b' mentioned above. I'm reading that UI stuff should be on the main thread but it seems like that could be both 'b' and 'c' above.
And just an FYI, I'm using this to start the timer 'b' above:
[NSThread detachNewThreadSelector:@selector(startObjectsAnimation toTarget:animationHelper withObject:nil];
Then in animationHelper:
NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
animationTimer = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(doAnimation userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:animationTimer forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] run];
Curious what people's thoughts are about this.
Thanks in advance.
|Mar 2, 2009, 07:54 PM||#2|
Additional I see some people mention creating their own loop with a sleep interval instead of just using an NSTimer:
[self performSelectorOnMainThread:@selector(updateInterface) withObject:nil waitUntilDone:NO];
Is that better for any reason than NSTimer?
|Thread Tools||Search this Thread|
|thread||Thread Starter||Forum||Replies||Last Post|
|OSX- main thread is in wait how to get intrrupt pipe response||login4vinay||Mac Programming||1||Mar 7, 2014 03:00 AM|
|IGN Monthly Free Game - Main Thread||ValtermcPires||iPhone and iPod touch Apps||12||Nov 1, 2013 09:21 PM|
|Get image data for pins on a MapView without blocking main thread problem||pan17||iPhone/iPad Programming||4||Jul 25, 2012 08:26 PM|
All times are GMT -5. The time now is 07:48 PM.