Search code examples
iosswiftsprite-kitspritesknode

Spritekit SkNodes intersection's Rect / Polygon


I want to determinate the intersection's Rect / Polygon of 2 overlapping SkNodes in Sprite-kit.

The method :

SKNode.intersectsNode(<#T##SKNode#>)

returns only true or false if there is an intersection, but i want to know also the intersection's area.

Can somebody help me? (I want to determinate the green triangle)

enter image description here


Solution

  • Googling "area of intersection of two rectangles" shows this has been addressed multiple times on SO, like here, and here.

    As far as Sprite Kit specific: you are going to have to implement some logic (to test for intersection, containment, etc...) and math (to calculate the area of the intersection,) AFAIK there is nothing built into SK to do it for you.