Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何根据屏幕大小/设备改变脉冲/速度_Ios_Swift_Sprite Kit - Fatal编程技术网

Ios 如何根据屏幕大小/设备改变脉冲/速度

Ios 如何根据屏幕大小/设备改变脉冲/速度,ios,swift,sprite-kit,Ios,Swift,Sprite Kit,我正在用swift构建一个游戏,在这个游戏中,你必须避免精灵在屏幕上移动。当我在iphone 5上测试游戏时,这些物体比在6或6+上更难避免。我想这是因为我的速度是一样的(我根据屏幕大小调整大小)。我改变了最初的冲动,尝试根据屏幕大小改变,并将我最初用于CGVector的数字与此匹配 let gOneX = screenWidth/6 let gOneY = screenHeight/9 let gTwoX = screenWidth/6 let gTwoY = screenHeight/9

我正在用swift构建一个游戏,在这个游戏中,你必须避免精灵在屏幕上移动。当我在iphone 5上测试游戏时,这些物体比在6或6+上更难避免。我想这是因为我的速度是一样的(我根据屏幕大小调整大小)。我改变了最初的冲动,尝试根据屏幕大小改变,并将我最初用于CGVector的数字与此匹配

let gOneX = screenWidth/6
let gOneY = screenHeight/9
let gTwoX = screenWidth/6
let gTwoY = screenHeight/9

ghostOne.physicsBody?.applyImpulse(CGVectorMake(gOneX, -gOneY))
ghostTwo.physicsBody?.applyImpulse(CGVectorMake(-gTwoX, gTwoY))
我这样做了,这足以让我注意到设备之间的差异,但这仍然是不可接受的。基于设备,这些对象更难或更容易避免

let gOneX = screenWidth/6
let gOneY = screenHeight/9
let gTwoX = screenWidth/6
let gTwoY = screenHeight/9

ghostOne.physicsBody?.applyImpulse(CGVectorMake(gOneX, -gOneY))
ghostTwo.physicsBody?.applyImpulse(CGVectorMake(-gTwoX, gTwoY))

有没有其他方法可以改变脉冲?

当然可以。根据屏幕大小设置您自己的手动值。我该怎么做?If语句?If语句可以正常工作。如何找出它们在哪个设备上?每个设备都有一个屏幕宽度/高度。还有其他方法。谷歌(Google)类似iOS的东西决定了使用哪种设备或类似设备。
let gOneX = screenWidth/6
let gOneY = screenHeight/9
let gTwoX = screenWidth/6
let gTwoY = screenHeight/9

ghostOne.physicsBody?.applyImpulse(CGVectorMake(gOneX, -gOneY))
ghostTwo.physicsBody?.applyImpulse(CGVectorMake(-gTwoX, gTwoY))