ios - Using separate functions on different collision categories -
i'm designing game (ios swift, sprite kit) 3 skphysics-categories:
- player
- objects
- platforms
when collision between either 1 of these categories occurs, follow function runs:
func didbegincontact(contact: skphysicscontact) { println("collision") self.gameover = true } this fine when player , object collide, shouldn't run when player walks on platform.
how can set specific functions collisions between categories? or, rephrase question, how can specify different collisions inside of above-mentioned function?
thanks, guys!
you should take contact parameter , use properties. bodya , bodyb allow differentiate between bodies have had collision occur. put these in if statement follows,
if((bodya.physicsbody == hero.physicsbody) && (bodyb.physicsbody == platform.physicsbody)){ //perform relevant code } else if((bodya.physicsbody == hero.physicsbody) && (bodyb.physicsbody == heartpickup.physicsbody)){ //perform relevant code } this allow run different sections of code depending on sprites/physics bodies have been connecting.
Comments
Post a Comment