在 cocos2d-x 中,若要讓遊戲適配 iPhone 6 或更高螢幕,可從方向設定、啟動圖與場景尺寸三方面著手。本文提供一種簡單做法。
在 RootViewController.mm 中支援橫向或直向:
- (NSUInteger)supportedInterfaceOrientations {
#ifdef __IPHONE_6_0
return UIInterfaceOrientationMaskLandscape;
#endif
}
若遊戲為橫向,可回傳 UIInterfaceOrientationMaskLandscape;若為直向,則回傳對應的直向遮罩。
手動匯入 Default-568h@2x.png 等啟動圖。若缺少對應尺寸圖片,上下可能出現黑邊。
可透過 CCDirector 取得場景尺寸,再依高度判斷是否為 iPhone 6 螢幕:
CCSize size = CCDirector::sharedDirector()->getWinSize();
if (size.height == 1136) {
// 調整布局
}
cocos2d-x 的適配方式會受版本影響。較新版本可搭配 resource 目錄與 design resolution 機制。若專案仍使用舊版,手動判斷尺寸雖然簡單,但維護成本較高。