为iphone 4s和iphone 5编写cocos2d代码

时间:2013-05-29 12:07:02

标签: ios cocos2d-iphone

我知道cocos2d可以考虑使用

在iphone或ipad上运行代码
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)    {

} 

但是我可以写cocos2d代码考虑到iphone屏幕的两种尺寸。例如:

#define xPosition1 120.0
#define xPosition2 240.0
#define xPosition3 360.0

if (iphone5) {
        #define xPosition1 142.0
        #define xPosition2 284.0
        #define xPosition3 426.0
}

1 个答案:

答案 0 :(得分:1)

一种方法是使用以下方法:

CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;

这将根据您的设备返回屏幕宽度和高度。这意味着,iPhone 4S将返回320 x 480,iPhone 5将返回320 x 568