-1

I am trying to delete the objects after it go outside the scene so so i can extenuate ram consumption

I should put the code i have tried but i dont know how to begin so i have nothing to put here sorry

EDIT

Or maybe i should detect if the object inside the view and delete it if not how i can know if the object is inside the view ?

RUON
  • 163
  • 9

2 Answers2

1

There is a convenient method which checks whether two CGRects intersect each other or not

You can do something like this

if( CGRectIntersectsRect(object.frame, view.frame) ) {
   // Don't delete your object
} else {
   // Delete your object as it is not in your view
}

I hope this helps :)

lazyDroid
  • 15
  • 2
1

You can check in different ways if node is off-screen, and that depends on how you move nodes.

First method :

if (!intersectsNode(yourNode)) {
     // node is off-screen
}

To enumerate nodes you can use : - enumerateChildNodesWithName:usingBlock: To access all nodes in a node tree read this.

Another way is to use actions:

let move = SKAction.moveTo(location: offScreenLocation, duration: 5)

let remove = SKAction.runBlock({yourNode.removeFromParent()})

let sequence = SKAction.sequence([move,remove])

yourNode.runAction(sequence, withKey:"moving") //Use action with key, to cancel the action if needed

Third method would be to use contact detection.

Community
  • 1
  • 1
Whirlwind
  • 14,286
  • 11
  • 68
  • 157