Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 1, 2009, 07:16 PM   #1
99miles
macrumors member
 
Join Date: Oct 2008
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];
[autoreleasepool release];

Curious what people's thoughts are about this.

Thanks in advance.
99miles is offline   0 Reply With Quote
Old Mar 2, 2009, 06:54 PM   #2
99miles
Thread Starter
macrumors member
 
Join Date: Oct 2008
Additional I see some people mention creating their own loop with a sleep interval instead of just using an NSTimer:

while (notDone)
{
[self performSelectorOnMainThread:@selector(updateInterface) withObject:nil waitUntilDone:NO];
[NSThread sleepForTimeInterval:0.5f];
}


Is that better for any reason than NSTimer?
99miles is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
How many hours usage do you get on your iPad 2? The Game 161 iPad 14 May 6, 2011 03:53 AM
How many degrees should the mac be? issiciby MacBook Pro 2 Jun 4, 2010 03:53 PM
Which files should be deleted and how? Follon iPhone Tips, Help and Troubleshooting 0 May 11, 2008 03:35 PM
Poll -- How many more stupid iPhone reports on MacRumors before release? WannaGoMac Community Discussion 11 Jun 21, 2007 10:49 AM
How many GBs should the VM be? musicpyrite Mac Applications and Mac App Store 4 Apr 24, 2004 07:10 PM


All times are GMT -5. The time now is 07:52 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC