简体   繁体   中英

Sprite Kit game for Iphone 3.5 inch and 4 inch screen size

I have developed a little game in Sprite Kit with Xcode 5 for a 4-inch screen, but I would like to know if and how can I use it with a 3.5-inch. When I open the app with an iPhone 5, everything is OK, but if I try to open it with an iPhone 4S simulator, a lot of things are hidden outside of the screen.

I read a lot of posts and the solution seems to be constraints, but it is the best solution? Does it work with SpriteKit? How can use it?

For example I positioned a child like this:

AAShareBubbles *shareBubbles = [[AAShareBubbles alloc] initWithPoint:CGPointMake(self.view.frame.size.width/2, (self.view.frame.size.height/2)+170)

170 is absolute position. About (height/2)+170 is OK for a 4-inch screen, but not for a 3.5-inch screen.

there are many ways you can do it for different device either create different textureAtlas for different device size or easiest way to change the SKView

for eg

add this line to your 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];


}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM