I extended SKSpriteNode
with my own class to have more functions.
But how can I get this extended node when something 'hits' this node and didBeginContact
is called?
Because contact.bodyA
and contact.bodyB
are physicsBody and parent of this is the game scene.
This is my subclass of SKSpriteNode:
class Orange: SKSpriteNode {
...
func createPhysicsBody(){
self.physicsBody = SKPhysicsBody(circleOfRadius: self.size.width / 2)
self.physicsBody?.dynamic = true
...
}
}
This is my didBeginContact code:
func didBeginContact(contact: SKPhysicsContact){
switch(contact.bodyA.categoryBitMask + contact.bodyB.categoryBitMask){
case orangeCategory + bulletCategory:
contactOrangeBullet(contact.bodyA, bodyB: contact.bodyB)
break;
default:
break;
}
}
In contactOrangeBullet
is just code that handles everything when this case happens. But I need more than physicsBody
. I need the 'Orange' which physicsBody
is just a part of.
Or do I understand something wrong and this is not possible because physicsBody does not stick to 'Orange' although it was created in there?
Orange
class functions and attributes. – Glucosuria