swift - SpriteKit : can not see existing node's children

标签 swift sprite-kit nodes

我正在使用 SpriteKit 构建游戏。这是我的节点树:self.world.hydraAnchor.head

问题是 head看不见

代码简单

let world = SKSpriteNode()
addChild(world)
...
let hydraAnchor = SKSpriteNode()
hydraAnchor.position = anchorsPosition
world.addChild(hydraAnchor)

let head = SKSpriteNode(imageNamed: "hydraHead")
head.position = CGPointMake(anchorsPosition.x, anchorsPosition.y + 50)
hydraAnchor.addChild(head)

我看不到head在构建项目时,同时 println(hydraAnchor.children)给出 [<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'hydraHead' (50 x 50)] position:{700.50396728515625, 2486.333251953125} size:{25, 25} rotation:0.00]

当而不是添加 head 时至 hydraAnchor我这样做:

world.addChild(head)

head可见。

zPosition , invisiblealpha属性与问题无关。

最佳答案

您忘记了节点的子节点的坐标系与父节点的坐标系不同。您的父节点的“worldNode”位置可能位于 x:500、y:500 并且在父节点顶部添加一个子节点 20 点将变为 x:0 y:20。

您正在使用 worldNode 坐标而不是父坐标添加子节点。

关于swift - SpriteKit : can not see existing node's children,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30847346/

相关文章:

javascript - D3、SVG 和 JavaScript : Need to assign unique images to dynamically created nodes

Xcode 链接器命令失败,退出代码为 1

node.js - 无法访问对象内部的数据

windows - Windows 节点上的 Kubernetes NAT pod IP

Azure 通知中心上的 iOS 推送通知

ios - SpriteKit - 生成随机节点

objective-c - SpriteKit enumerateChildNodesWithName 高级搜索?

swift - 如何将 ARHitTestResult "convert"转换为 ARRaycastResult?

ios - 使用 swift 后丢弃 View

ios - Swift Dictionary 在键后为 [String] 类型的值添加方括号