Hi Ive got an funny problem.. Forst of all my code:
- (void)viewDidLoad
{
[super viewDidLoad];
didStart=YES;
[NSThread detachNewThreadSelector:@selector(updateGame:) toTarget:self withObject:nil];
}
-(void)updateGame:(id)sender{
while (1) {
NSLog(@"getting called");
CGRect frame= self.label.frame;
frame.origin.y+=1;
self.label.frame=frame;
[self.label removeFromSuperview];
[self.view addSubview:self.label];
NSLog(@"%f",frame.origin.y);
}
}
Basically I am implementing a game loop. But although I am assured the loop is getting called, somehow the label is not moving on the screen. Any thoughts what could be the problem?
From the UIKit Framework Reference:
If your game world update code is fast, you can just use an
NSTimerto run the game update on the main thread periodically.If your game world update code is slow, you will want to run it on a background thread, updating model objects. Then you notify the main thread (perhaps using
dispatch_asyncorperformSelectorOnMainThread:withObject:waitUntilDone:) to update the UI. But if you can run your update code on the main thread, you will be much less prone to multithreading problems like race conditions.