I'm working on Collision Detection where the hope is when Object1 moves down the screen and eventually hits Object2 it triggers the didBeginContact method and in turn, the resetPosition on Object1 which will bring Object1 back to the top of the screen. I've used NSLogs to test to make sure if the program reaches the didBeginContact method, and it does. On top of that, the program also works through the called upon method (resetPosition) as well. The only problem is, it does not change the position of Object1. I the tried to see if I could call the method resetPosition in the touchesBegan method, and it works. Object1's position is actually reset. Are there limitations to what you can do in the didBeginContact method? And if so, what would be the best way of trying to achieve my intended goal.
Here is a sample of my didBeginContact Method:
-(void)didBeginContact: (SKPhyicsContacts *)contact {
SKPhysicsBody *firstBody, *secondBody;
if(contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask){
firstBody = contact.bodyA;
secondBody = contact.bodyB;
} else {
firstBody = contact.bodyB;
secondBody = contact.bodyA;
}
if(firstBody.categoryBitMask == Category1 && secondBody.categoryBitMask == Category2){
NSLog(@"Collision Detected!");
[Object1 resetPosition];
}
To clarify any confusion, Category1 corresponds to Object1, Category2 corresponds to Object2.
Here is a sample of my resetPosition method inside of my Object1 class:
-(void)resetPosition{
self.position = CGPointMake(0, 200);
NSLog(@"Reached Method!");
}