Reputation: 7147
I would like to add a new superpower to my superhero in a spritekit game.
Once this superpower is enabled, he will be able to pass through any other SKPhysicsBody.
Setting the contactTestBitMask to 0x00000000 will only disable contact detection (didBeginContact:).
self.hero.physicsBody.contactTestBitMask = 0x00000000;
while setting dynamic to NO will let it pass through any SKPhysics body (but at the same time it will disable the gravitational force as well)
self.hero.physicsBody.dynamic = NO;
I want it to pass through the hero instead of just disabling the contact detection.
How to achieve this?
Upvotes: 0
Views: 415
Reputation: 11
Add a variable to tell if you have the power-up, then set it to true
when you run the function that activates your power-up.
In the didBegin
function, you should then add a guard else { return }
statement with the conditional being the variable name == true
. The only thing to be careful of is to set the variable back to false
when the power-up is disabled, or the power-up will continue forever.
(Just to be clear, this is in 2024 with slightly outdated Swift 5.5. I am guessing that a solution didn't exist in 2014, but I don't know as that was before I was born!)
Upvotes: 0