适用于iPhone 3.5英寸和4英寸屏幕尺寸的Sprite Kit游戏

时间:2014-08-17 21:59:41

标签: ios objective-c iphone

我在Sprite Kit中开发了一款带有Xcode 5的小游戏用于4英寸屏幕,但我想知道是否以及如何使用3.5英寸屏幕。当我用iPhone 5打开应用程序时,一切正常,但如果我尝试使用iPhone 4S模拟器打开它,屏幕外会隐藏很多东西。

我阅读了很多帖子,解决方案似乎是限制因素,但这是最好的解决方案吗?它适用于SpriteKit吗?怎么用呢?

例如,我为这样的孩子定位:

AAShareBubbles *shareBubbles = [[AAShareBubbles alloc] initWithPoint:CGPointMake(self.view.frame.size.width/2, (self.view.frame.size.height/2)+170)
170是绝对的位置。关于(高度/ 2)+170适用于4英寸屏幕,但不适用于3.5英寸屏幕。

1 个答案:

答案 0 :(得分:1)

您可以通过多种方式为不同的设备创建不同的设备大小或更改SKView的最简单方法

例如

将此行添加到viewController

#define IS_WIDESCREEN ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON ) 


-(void)addLoadingScene
{

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {

        if (IS_WIDESCREEN) {
            //this code for iPhone 4 inches 

           //get device type _deviceType=iphonebig;
            //define globalscaleX and globalscaleY in header fine
            //where skview is reference of your view


            _globalscaleX=(1024.0f*2)/(568*2);
            _globalscaleY=(768.0f*2)/(320*2);

            yourfirstScreen = [loadingScene sceneWithSize:CGSizeMake(_SKView.bounds.size.height*_globalscaleX, _milkhuntSKView.bounds.size.width*_globalscaleY)];

                //please take a look at all the scaleMode defined by spritekit

               yourfirstScreen.scaleMode = SKSceneScaleModeFill;
        } else {
        //this code for iPhone 3.5 inches 

            _deviceType=iphone;
            _globalscaleX=(1024.0f*2)/(480*2);
            _globalscaleY=(768.0f*2)/(320*2);

            yourfirstScreen = [loadingScene sceneWithSize:CGSizeMake(_SKView.bounds.size.height.bounds.size.height*_globalscaleX, _SKView.bounds.size.height bounds.size.width*_globalscaleY)];
             yourfirstScreen.scaleMode = SKSceneScaleModeFill;
        }

    } else {

          //this code for iPad
        _deviceType=ipad;
        _globalscaleX=1.0f;
        _globalscaleY=1.0f;

        LoaderScreen = [loadingScene sceneWithSize:CGSizeMake(_SKView.bounds.size.height.bounds.size.height, _SKView.bounds.size.height.bounds.size.width)];
       yourfirstScreen.scaleMode = SKSceneScaleModeAspectFill;
    }


     [_SKView presentScene:LoaderScreen];


}