Hey
I am quite new too coding and I hope someone can maybe clear me up.
1) Right after game scene I wrote
2) In func didBeginContact I have this after the standard variables
Everything is working as expected because when the collision happens the "collisionBulletWithWorldBorder(WorldBorder:SKNode, Bullet:SKSpriteNode)" function is called which than removes my bullet.
(Bullet is not in game scene so I cannot just write bullet.removeFromParent() instead of the paragraph with the bold bit)
However if I try to change the code (bold) to ... as! SKNode, because my common sense tells me too, than it will not work anymore. Can someone explain why this bit is SKSpriteNode and not just SKNode.
Thanks for any help
SOLVED: just remove the whole collision bullet with world border line and replace it with Firstbody(or secondbody).node?.remove from parent. Duh
I am quite new too coding and I hope someone can maybe clear me up.
1) Right after game scene I wrote
Code:
let worldBorder = SKNode()
2) In func didBeginContact I have this after the standard variables
Code:
if ((firstBody.categoryBitMask == physicsCategory.bullet) && (secondBody.categoryBitMask == physicsCategory.worldBorder) ||
(firstBody.categoryBitMask == physicsCategory.worldBorder) && (secondBody.categoryBitMask == physicsCategory.bullet)) {
collisionBulletWithWorldBorder([B]firstBody.node as! SKSpriteNode[/B], Bullet: secondBody.node as! SKSpriteNode)
Everything is working as expected because when the collision happens the "collisionBulletWithWorldBorder(WorldBorder:SKNode, Bullet:SKSpriteNode)" function is called which than removes my bullet.
(Bullet is not in game scene so I cannot just write bullet.removeFromParent() instead of the paragraph with the bold bit)
However if I try to change the code (bold) to ... as! SKNode, because my common sense tells me too, than it will not work anymore. Can someone explain why this bit is SKSpriteNode and not just SKNode.
Thanks for any help
SOLVED: just remove the whole collision bullet with world border line and replace it with Firstbody(or secondbody).node?.remove from parent. Duh
Last edited: