开发者

Manually controlling framerate of Cocos2d-iPhone game strategy

开发者 https://www.devze.com 2023-02-24 23:11 出处:网络
Most game developers should have encountered the \"low framerate\" issue at least once when developing games. But I, on the other hand, am making a sudoku-like puzzle game where low framerate is not a

Most game developers should have encountered the "low framerate" issue at least once when developing games. But I, on the other hand, am making a sudoku-like puzzle game where low framerate is not a problem since it does not have constantly moving sprites/elements, and in fact I plan to decrease the framerate so that the game will take less CPU time and hence reduce the power consumption of the iDevices; all this just as a courtesy to the players :)

I already know that I can control the framerate in Cocos2d-iphone by modifying animationInterval:

[[CCDirector sharedDirector] setAnimationInterval:1.0/60];

But I'm having troubles on the strategy on when to lower the framerate and when to revert to the normal framerate (60Hz). At this point I only managed to define the strategy for touch event, that is:

Start with lower framerate. On ccTouchBegan, revert to normal framerate. On ccTouchEnded, switch to lower 开发者_C百科framerate. Make sure multitouch is handled accordingly.

I'm left with two more conditions:

  1. Handling CCActions on CCNodes: as long as some CCNodes have running actions, revert to normal framerate.

  2. Particle system: as long as there exist some particle systems that are emitting particles, revert to normal framerate.

Basically I need to be able to detect if there are actions that are still running on any sprites/layers/scene, also if some particle systems are still emitting particles. I prefer to not having the checking done on individual objects, and I'd rather have a simple [SomeClass isActionRunning]. I imagine that I might be able to do this by checking the list of "scheduled" object but I'm not sure how. I'd appreciate if you could also suggest some other conditions where I need to revert to normal framerate.


Hmm.. I would recommend that you set it to 30fps.. Yes.. Its the rate that screen refreshes.. But the most important is how you code the game.. It must be efficient.. Rather than running extra processes checking if something is running or not.. It may eat up slightly more processing power..


though i know it's not a very clean way but you can hack CCScheduler class and check if there are any object in scheduledMethods. and i guess you have to check if the objects there are yours since cocos2d itself schedule some classes.


This might be what you are looking for, at least regarding actions.

When you run an action you can call a block at the end of your action, in which you reset the frame rate.

[[CCDirector sharedDirector] setAnimationInterval:1.0/60];//set your fast frame rate
[self runAction:[CCSequence actions:
                 [CCMoveBy actionWithDuration:0.5f position:ccp(100,100)], //Do whatever action it is you want to do
                 [CCCallBlock actionWithBlock:^
                  {
                      [[CCDirector sharedDirector] setAnimationInterval:1.0/30]; //Revert to slow frame rate... could also check within the block for other actions
                  }],
                 nil]];
0

精彩评论

暂无评论...
验证码 换一张
取 消