I want to use allContactedBodies instead of didBeginContact & didEndContact.
When I do :
NSLog(@\"%@\", node.physicsBody.allContactedBodies );
<
If you read the SKPhysicsBody Class Reference, you should have seen the format for this command.
- (NSArray *)allContactedBodies
The return value is:
An array of SKPhysicsBody objects that this body is in contact with.
Having said that, you would use this code to accomplish what you are asking:
NSArray *tempArray = [yourNode.physicsBody allContactedBodies];
for(SKNode *object in tempArray)
{
if([object.name isEqualToString:@"theBall"])
NSLog(@"found the ball");
}
FYI - You will have to run this code in the update:
method. This means your app will spend precious processing time every single frame checking for a contact. It would make much more sense to stick with the didBeginContact:
instead.