I want to use allContactedBodies instead of didBeginContact & didEndContact.
When I do :
NSLog(@\"%@\", node.physicsBody.allContactedBodies );
<
The allContactedBodies
property returns an array of SKPhysicsBody objects. You can access the node to which each physicsBody is attached by using the node
property of SKPhysicsBody
NSArray *tempArray = [yourNode.physicsBody allContactedBodies];
for(SKPhysicsBody *body in tempArray)
{
if([body.node.name isEqualToString:@"theBall"])
NSLog(@"found the ball");
}
In Swift the same code above can be written like:
val ballNode: SKNode? = yourNode.physicsBody.allContactedBodies().first(where { $0.node.name == "theBall" })?.node