iPad和iPhone之间的SpriteKit坐标不同 [英] SpriteKit Coordinates differ between iPad and iPhone

查看:66
本文介绍了iPad和iPhone之间的SpriteKit坐标不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的SpriteKit场景,其行为不像我期望的那样。这是一个通用应用程序,我用于在场景中绘制单个红色正方形的代码如下:

I have a very simple SpriteKit scene that is not behaving like I would expect. It is a universal app and the code that I am using to draw a single red square in the scene is as follows:

    let redSquare = SKSpriteNode(color: UIColor .redColor(), size: CGSizeMake(100.0, 100.0))
    redSquare.anchorPoint = CGPointMake(0.0, 0.0)
    redSquare.position = CGPointMake(1.0, 1.0)
    addChild(redSquare)

此代码位于xCode默认应用程序的GameScene didMoveToView方法中在您选择SpriteKit游戏时会为您创建。

This code is in the GameScene didMoveToView method of the default app that xCode creates for you when you select SpriteKit game.

在iPad上运行时,它的行为与预期的一样,在屏幕的底部和左侧边缘绘制了红色方块1。

When run on the iPad it behaves as expected drawing the red square 1 point off the bottom and left edge of the screen.

当我在iPHone 6 Plus模拟器上运行它时,它显示如下:

When I run it on the iPHone 6 Plus simulator however it shows up like this:

宇宙飞船出现在更正处在两个设备上都没有t接触点,但是触摸位置的println()在iPad上显示(1,1),在iPhone上显示(1100)。
这表示(x,0)-(x,99)的坐标不在iPhone屏幕的底部,这对我完全没有意义。

The spaceship shows up at the correct touchpoint on both devices, however a println() of the touch location shows (1,1) on the iPad and (1,100) on the iPhone. This indicates that the coordinates from (x,0) - (x,99) are off the bottom of the iPhone screen which makes no sense to me at all.

为什么两个设备不能以相同的方式显示它?在模拟器和实际设备上,行为都是相同的。

Why do the two devices not display it the same way? The behavior is the same in both the simulators and on the actual devices.

谢谢!
滑板车

Thanks! Scooter

推荐答案

这是因为iPhone上的屏幕尺寸不正确-请在场景中查看sks文件中,您应该看到默认情况下场景的大小设置为(1024,768)。要解决此问题,您需要设置场景大小和缩放模式:

This is caused because the size of the screen on iPhone is incorrect - have a look in the scene's sks file, you should see the size of the scene is set to (1024, 768) by default. To correct this you need to set the scene size and scale mode:

scene.size = skView.bounds.size
scene.scaleMode = .AspectFill

您应该执行的操作是 didMoveToView 或实例化场景。

You should do this is didMoveToView or when you instantiate the scene.

这篇关于iPad和iPhone之间的SpriteKit坐标不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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