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

查看:16
本文介绍了使用 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).

我有一个继承自 SKScene 的 GameScene 类.我只是想使用各种坐标将 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)

然后使用

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天全站免登陆