I am trying to figure out how to determine if a node is visible on the screen or off the screen. Is this just a true/false property of the node? Thanks. (Using swift spritekit)
the best answer here will be:
if scene.frame.contains(myNode.position) {
//do stuff
}
"intersect" method is very heavy and involves too much computing, can produce lag if used on many instances
You can use the following to test if a node is in the scene:
if (!intersectsNode(sprite)) {
println("node is not in the scene")
}
This assumes that self
is an SKScene
subclass, such as GameScene
.
If you put a SKCameraNode in the scene, you can check if a node is inside the view of the camera using the contains
method:
https://developer.apple.com/documentation/spritekit/skcameranode
You can also get all the nodes visible to the camera using the containedNodeSet
instance method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With