我正在尝试弄清楚如何确定一个节点是否在屏幕上可见还是不可见。这仅仅是节点的真/假属性吗?谢谢。(使用Swift SpriteKit)
我试图弄清楚如何确定一个节点是否在屏幕上可见还是不可见。这只是一个节点的真/假属性吗?谢谢。(使用Swift SpriteKit)我正在尝试弄清楚如何确定一个节点是否在屏幕上可见还是不可见。这仅仅是节点的真/假属性吗?谢谢。(使用Swift SpriteKit)
我试图弄清楚如何确定一个节点是否在屏幕上可见还是不可见。这只是一个节点的真/假属性吗?谢谢。(使用Swift SpriteKit)if (!intersectsNode(sprite)) {
println("node is not in the scene")
}
这假设self
是SKScene
的子类,例如GameScene
。
backgroundNode.anchorPoint = CGPoint(x:0.5,y:0.5)
和 backgroundPoint.position = CGPoint.zero
。你可能需要相应地改变子节点的位置。 - 0x141Eif scene.frame.contains(myNode.position) {
//do stuff
}
"intersect"方法非常耗费计算资源,如果在多个实例上使用可能会导致卡顿。
https://developer.apple.com/documentation/spritekit/skcameranode
你还可以使用containedNodeSet
实例方法获取相机可见的所有节点。SKScene
适合其包含的view
,那么这应该可以工作:if !node.intersectsNode(node.parent!) {
// node is off-scene/out-of-view
}
其中node
是属于你的SKScene
子节点的SKNode
。
if (/*the node's position is between 0 and the screen's .x and .y*/) {
//on screen
}
CGRectIntersectsRect
,提供你的SKSpriteNode
和SKScene
的frame
。例如:if !CGRectIntersectsRect(frame, spriteNode.frame) {
// Outside the bounds of the scene because the frames are no longer intersecting.
}