本文整理自《Learn iPhone and iPad cocos2d Game Development》,歸納手機遊戲開發時幾個基本的注意事項。
程式啟動:applicationDidFinishLaunching
程式切到背景:applicationDidEnterBackground
程式執行結束:applicationWillTerminate
允許使用者設定裝置方向:
[[CCDirector sharedDirector] setDeviceOrientation:CCDeviceOrientationLandscapeLeft];
動畫幀週期:
[[CCDirector sharedDirector] setAnimationInterval:1.0/60];
保持遊戲運行在一個高的幀率是你的責任。當你設定了較低的幀率,且遊戲能穩定維持在該幀率時,使用者體驗會比使用一個較高但不穩定的幀率更好。理想狀態下,遊戲應運行在每秒 60 幀,尤其是動作遊戲;而大多數益智遊戲,每秒 30 幀即可滿足需求。
查看 FPS:
[[CCDirector sharedDirector] setDisplayFPS:YES];
日誌在 Debug 與 Release 中的差別:請用 CCLog,不要用 NSLog,後者在 Release 版本中依然存在,會影響程式運行。
型別轉換的防禦性程式設計:
CCNode* node = [self getChildByTag:13]; // 防禦性程式設計:驗證回傳的節點是否為 CCLabel 類別的物件 NSAssert([node isKindOfClass:[CCLabel class]], @"node is not a CCLabel!");
測試時盡量用 Release Configuration,而非 Debug Configuration。