I am trying to fix an issue I am having with the SKPhysicsContactDelegate collision detection. I have two nodes, nodeA and nodeB, nodeA is stationary on the screen while nodeB is able to be dragged around the screen by the users finger. nodeA needs to be able to detect if nodeB is overlapping it. The didBeginContact and didEndContact methods are being called multiple times which through research I have found to be an expected behavior. To get around this issue I simply set an integer variable to 0 and increment it each time there was a contact and decrement it each time a contact ended. If the value is greater than 0 then the two nodes are overlapping and if the value is equal to 0 then they are not. This works fine until the user drags nodeB over nodeA too fast. When this happens the contact methods are not always called the correct amount of times. For example, there may be 3 contacts detected but only two end contacts (or even none), which makes the program think that the two nodes are still overlapping even when they are not. I am assuming that this is happening because the user is dragging the node faster than the program can update. Is there anything I can do to get around this? Basically I just need to know exactly when the two nodes are overlapped and when they are not. Also note that the nodes are convex shapes. Below are my contact methods:
func didBeginContact(contact: SKPhysicsContact)
{
let contactMask = contact.bodyA.categoryBitMask + contact.bodyB.categoryBitMask
if contactMask == 3
{
startContact++
timerStart = true
}
}
func didEndContact(contact: SKPhysicsContact)
{
let contactMask = contact.bodyA.categoryBitMask + contact.bodyB.categoryBitMask
if contactMask == 3
{
startContact--
if startContact == 0
{
timerStart = false
}
}
}