使用Swift理解坐标系SpriteKit的问题 [英] Problems understanding coordinate system SpriteKit using Swift

查看:130
本文介绍了使用Swift理解坐标系SpriteKit的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用Swift完全掌握SpriteKit的坐标系。我看过很多资源,包括苹果开发文档,但由于某些原因我很困惑(我确定这一定很简单)。

I am having trouble fully grasping the coordinate system with SpriteKit using Swift. I have looked at many resources including apples dev docs but for some reason I am very confused (i'm sure this must be simple).

我有一个继承的GameScene类来自SKScene。我只是尝试使用各种坐标将SKSpriteNode添加到屏幕以适应屏幕布局。我相信当你创建任何SKNode并通过执行以下操作给它一个位置时

I have a GameScene class inheriting from SKScene. I am just trying to add a SKSpriteNode to the screen using various coordinates to get used to the screen layout. I believe that when you create any SKNode and give it a position by doing the following

var node = SKSpriteNode(color: UIColor.brownColor(), size: CGSizeMake(100, 100))
node.position = CGPointMake(0, 0)

然后放置任何SKNode

and then place any SKNode using

self.addChild(node)

提供给节点的坐标是父节点中的坐标。这是否意味着已经创建的棕色方块应该放在左下角?

The coordinates that have been supplied to the node are coordinates in the parent node. Does this mean that the brown square that has been created should be placed at the bottom left corner?

这显然不是这种情况,这让我感到困惑。我正在使用iPhone 5s模拟器进行纵向测试。

This is obviously not the case and is what is confusing me. I am using the iPhone 5s simulator for testing in portrait.

当我将位置设置为(350,50)时,精灵节点仅出现在左下角。

The sprite node only appears in the bottom left when I set the position to (350, 50).

推荐答案

在Project Navigator中选择 GameScene.sks ,选择 SKScene (它应该有一个黄色边框)并将其大小属性设置为320点x 569点(这是假设iPhone5 / 5S)这两种方式都是问题所在。还要确保你仔细检查它,因为我确定它已经改回到我的1024x768,但现在似乎正在工作。

Select the GameScene.sks in the Project Navigator, select the SKScene (it should have a yellow border round it) and set its size property to 320 points x 569 points (this is assuming iPhone5 / 5S) either way this is the problem. Also make sure you double check it as I am sure it changed back to 1024x768 on me, but seems to be working now.

这篇关于使用Swift理解坐标系SpriteKit的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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