iphone - FPS Lag scheduler? -
i've been getting fps lag. i've looked around , people use
[self schedule:@selector(gameloop:) interval: 1/60.0f];
when use choppy lag. when use
[self schedule:@selector(gameloop:)];
it's lot smoother. here snippet of movement code.
- (void)gameloop :(cctime)dt { [self managecannon:dt]; [self managebullets:dt]; [self manageenemies:dt]; [self manageallies:dt]; } - (void) manageenemies :(cctime)dt { enemyclass *tempenemy; for(int = 0; < [enemies count]; i++) { tempenemy = [enemyclass new]; tempenemy = [enemies objectatindex:i]; tempenemy.position = ccp(tempenemy.position.x-tempenemy.speed*dt,tempenemy.position.y); if((tempenemy.position.x - tempenemy.range) < [wall getwally]) { tempenemy.speed = 0; } if(tempenemy.health < 1) { tempenemy.alive = false; } if(tempenemy.alive == false) { [enemies removeobjectatindex:i]; [tempenemy removefromparentandcleanup:true]; } } }
i try write own code scratch, if can me out other things i'm doing incorrect helpful towards me.
it's hard slowing down app information given. learncocos2d suggested, can use instruments figure out slow stuff is. or if want granular analysis, can use following macros in code:
#define tic start = [nsdate date] #define toc -[start timeintervalsincenow] #define tocp nslog(@"time: %f", toc)
before using, sure declare nsdate *start
in scope of use. put series of tic/toc or tic/tocp pairs in code print out times code taking in different places. can find bottlenecks way.
Comments
Post a Comment