how can i change my spritekit on collision in spritekit swift -
how can change spritekit on collision in spritekit swift.
else if collidedbird.birdtype == 6 { if uidevice.currentdevice().userinterfaceidiom == .pad { _bird.physicsbody?.applyimpulse(cgvectormake(0, birdimplusereturn(70.0))) } else { _bird.physicsbody?.applyimpulse(cgvectormake(0, birdimplusereturn(70.0))) } let fire = nstimer.scheduledtimerwithtimeinterval(0.05, target: self, selector: selector("createdragonfire"), userinfo: nil, repeats: false) playeffectsound("bs_std_jump_sfx.mp3") _platform.removefromparent() }
if want change image of sprite, should use skphysicscontactdelegate method.
in general means have implement skphysicscontactdelegate, make new struct:
for example:
struct physiccategories { static let nonec : uint32 = 0x1 << 0 static let bird : uint32 = 0x1 << 1 static let platformc : uint32 = 0x1 << 2 static let finishc : uint32 = 0x1 << 3 static let obstaclec : uint32 = 0x1 << 4 } then go in didmovetoview() function , write:
physicsworld.contactdelegate = self dont forget make step!
then add func
func didbegincontact(contact: skphysicscontact) { var contactbody1 = contact.bodya var contactbody2 = contact.bodyb if contactbody1.categorybitmask < contactbody2.categorybitmask{ contactbody1 = contact.bodya contactbody2 = contact.bodyb } else { contactbody1 = contact.bodyb contactbody2 = contact.bodya } if ((contactbody1.categorybitmask == physiccategories.birdc) && (contactbody2.categorybitmask == physiccategories.obstaclec)){ // make gameover function that! // gameover() } if ((contactbody1.categorybitmask == physiccategories.birdc) && (contactbody2.categorybitmask == physiccategories.platformc)){ contactbody1.node.texture = sktexture(imagenamed: "") }
Comments
Post a Comment