Intersection Node s ---- Objective-C - Swift - iOS - SpriteKit Node

I am wondering why the following is not working correctly.

Before drawing nodes, I will analyze whether two specific nodes intersect using:

[[self playerSpriteNode] intersectsNode: [self pSKLabelNode]]

When pSKLabelNode touches the desired SpriteNode, it works great! (Returning true or false when it does not intersect)

But when it "passes" a few pixels from SKLabel, it still crosses and returns true.

Is there any setting recommended to fix the frame size of nodes or solutions that, in your opinion, will help solve the problem?

+4
source share
3 answers

, node ( ) node, ( ). :

if ([ninja intersectsNode:node] &&
    CGRectGetMinX(node.frame) <= CGRectGetMaxX(ninja.frame) &&
    CGRectGetMaxX(node.frame) >= CGRectGetMinX(ninja.frame))
{
    //and here I have intersects
}

,

+3

intersectNode . - "" , , , PNG.

, , .

, , INSIDE intersectsNode, . , , , x y intersectNode. - :

    if([[self playerSpriteNode] intersectsNode: [self pSKLabelNode]]){
        if(distance between x1 and x2 < size1.width/2 + size2.width/2 || distance between y1 y2 < size1.height/2 + size2.height/2){
            //Your code goes here
        }
    }

, x . , .

, , intersectsNode , , , . , , , intersectsNode true, , .

, , , , ; , .

+1

Swift 2.1:

To increase the results, do your check in a loop update( _:)where everything happens until the next picture:

override func update(currentTime: CFTimeInterval) {
        /* Called before each frame is rendered */

        if goodDude.intersectsNode(badDude){

            print("bad dude v.s. Ninja")

        }else{

            print("not dude at all")
        }

    }
0
source

Source: https://habr.com/ru/post/1527769/


All Articles