I am trying to delete node when goes out side the scene and i tried this method to do it
if( CGRectIntersectsRect(node.frame, view.frame) ) {
// Don't delete your node
} else {
// Delete your node as it is not in your view
}
but it seems not working any help would be appreciated
This is not going to be the best approach by a performance point of view but if you override the update
method in your scene you will be able to write code that gets executed each frame so.
class GameScene : SKScene {
var arrow : SKSpriteNode?
override func update(currentTime: NSTimeInterval) {
super.update(currentTime)
if let
arrow = arrow,
view = self.view
where
CGRectContainsRect(view.frame, arrow.frame) == false &&
CGRectIntersectsRect(arrow.frame, view.frame) == false {
arrow.removeFromParent()
}
}
}
Please keep in mind that every code you write inside the update method is executed each frame (60 times per second on a 60fps game) so you should be very careful about that.
Typical things you don't want to write inside the update
unless it is strictly necessary:
Hope this helps.