views:

435

answers:

3

I am new to iphone development. I used NSTimer scheduledTimerWithTimeInterval 0.01 seconds for game loop. The game consists drawscreen function inwhich I use CGContextClipToRect to clip the large images for animation. But the speed 0.01 seconds is working in simulator only not in the iphone(device). How can i overcome this problem? I respect your reply......you have told about it in previous post. But i could not understand..... the timer code is in view controller as

(void)viewDidLoad {
    GameView *main = [[GameView alloc] 
    initWithFrame:[[UIScreen mainScreen] applicationFrame]]; 
    main.backgroundColor = [UIColor blackColor]; 
    self.view = main; 
    [main release];    
    self.tim = [NSTimer scheduledTimerWithTimeInterval: 0.01         
    target: self selector: @selector (gameloop:) userInfo: nil repeats: YES]; 
    [super viewDidLoad];
}

Anyone can help me?

A: 

As U62 said, 100fps is not a realistic expectation, try running it at 30, maybe 60 updates a second and see how it runs. Also if your writing a game that need to run at a high frame rate you should look into writing it in OpenGL.

One option may be to process logic every tick, but only draw to the screen every few ticks.

Steve918
+1  A: 

NSTimer is the wrong tool for this job. It's not meant to be a real-time timer. It has no guarantees on when it will fire, and you can miss frames easily.

There are a lot of good recommendations for how to develop this kind of program on this thread. Note particularly the references to Apple's sample code.

Rob Napier
A: 

i mean ,for example when i animate frames ,frames are shown in correct speed in simulator. but in device it shows very slow(FPS)in other words a boy runs fastly in simulator.but in device he walks.