4 Replies
Latest reply on Feb 6, 2020 12:00 AM by hamimate
Level 1 (0 points)

I'm trying to figure out that a SKSpriteNode has completely iterated over another SKSpriteNode, this the code I have come up so far,

```if (node.frame.maxY == player.frame.minY){
}```

I know it's simple enough, but I'm lost here ;(

• ###### Re: know that skspritenode has completely moved over another skspritenode
Level 1 (0 points)

What do you mean by "iterated"? If I understand your subject correctly... This can be used when node 1 is just partially within the boundary of the second node:

`if node1.intersects(node2) {  }`

If you want to know, whether your first node is entirely within the boundaries of the second node, this should work:

```// Node 1 intersects HEIGHT of Node2
if  ( node1BottomY <= node2TopY && node1TopY >= node2BottomY ) || ( node1TopY >= node2BottomY && node1BottomY <= node2TopY )
{
intersectsHeight = true
}
// Node 1 intersects WIDTH of Node 2
if  ( node1LeftX <=node2RightX && node1RightX >= node2LeftX ) || ( node1RightX >= node2LeftX && node1LeftX <= node2RightX )
{
intersectsWidth = true
}

// If Node1 intersects both height and width of Node 2, it is completely withoin its boundaries:
if intersectsHeight == true && intersectsWidth == true {  }```

This is how you may check if half of the first node intesects the second node:

`if node2.contains(CGPoint(x: node1.frame.midX, y: node1.frame.midY)) `
• ###### Re: know that skspritenode has completely moved over another skspritenode
Level 1 (0 points)

let me clarify,

node 1 is static and node 2 is dynamic, I want to know when node 2 is completely out of node 1's boundaries.

• ###### Re: know that skspritenode has completely moved over another skspritenode
Level 1 (0 points)

if !node2.intersects(node1)

• ###### Re: know that skspritenode has completely moved over another skspritenode
Level 1 (0 points)

Set the contactTestBitMask properties of both objects. then detect when they collide in the didBegin func and then detect when they stop colliding in the didEnd func

```player.physicsBody?.contactTestBitMask = collisionTypes.bullet.rawValue