swift - EnumerateChildNodesWithName, Can't seem to Remove nodes -
i'm trying remove nodes parent node once reach x position. problem have parent node changing x position, children not changing x position inside parent (but moving parent), when put in if node.position.x < 300 . . . (remove node), nothing happens. tried below code, work 1 time , doesn't remove nodes again, i'm not 100% sure why stops working.
func cleanup() { let positionx = nodebase.position.x nodebase.enumeratechildnodeswithname("segment", usingblock: { node, stop in if node.position.x - positionx < 300 { node.removefromparent() } }) } can see going wrong code, or can point me in right direction?
try following:
nodebase.enumeratechildnodeswithname("segment") { node, _ in if !self.intersectsnode(node) { node.removefromparent() } } intersectsnode returns true whilst node inside bounds of skscene. therefore, when intersectsnode returns false know node offscreen , can remove node.
Comments
Post a Comment