如何在SpriteKit中支持多种屏幕尺寸? [英] How to support multiple screen sizes in SpriteKit?

查看:313
本文介绍了如何在SpriteKit中支持多种屏幕尺寸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作支持所有iOS设备的通用游戏,除了让项目如何让我的游戏支持所有屏幕尺寸之外还有一种方法可以通过代码检测屏幕尺寸并根据更改图形和代码大小,以及每个设备的图形分辨率应该是多少?

I want to make universal game that support all iOS devices , beside making the project how to make my game support all screen sizes is there is a way to detect the screen size by code and change the graphic and the code according to the size , and what should the resolution of the graphics for each device ?

推荐答案

使用此代码确定每个设备的宽度和高度屏幕。您还可以找出正在使用的设备。

Use this code to determine the width and height of the screen. You can also find out what device is being used.

    struct ScreenSize
{
    static let SCREEN_WIDTH         = UIScreen.mainScreen().bounds.size.width
    static let SCREEN_HEIGHT        = UIScreen.mainScreen().bounds.size.height
    static let SCREEN_MAX_LENGTH    = max(ScreenSize.SCREEN_WIDTH, ScreenSize.SCREEN_HEIGHT)
    static let SCREEN_MIN_LENGTH    = min(ScreenSize.SCREEN_WIDTH, ScreenSize.SCREEN_HEIGHT)
}

struct DeviceType
{
    static let IS_IPHONE_4_OR_LESS  = UIDevice.currentDevice().userInterfaceIdiom == .Phone && ScreenSize.SCREEN_MAX_LENGTH < 568.0
    static let IS_IPHONE_5          = UIDevice.currentDevice().userInterfaceIdiom == .Phone && ScreenSize.SCREEN_MAX_LENGTH == 568.0
    static let IS_IPHONE_6          = UIDevice.currentDevice().userInterfaceIdiom == .Phone && ScreenSize.SCREEN_MAX_LENGTH == 667.0
    static let IS_IPHONE_6P         = UIDevice.currentDevice().userInterfaceIdiom == .Phone && ScreenSize.SCREEN_MAX_LENGTH == 736.0
    static let IS_IPAD              = UIDevice.currentDevice().userInterfaceIdiom == .Pad && ScreenSize.SCREEN_MAX_LENGTH == 1024.0
}

您可以 println( )调试器中的值。

You can println() the values in the debugger.

这篇关于如何在SpriteKit中支持多种屏幕尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆