sprite kit - SKSpriteNode Collision Removal In Removing Wrong One With Xcode Swift SpriteKit -
i making game when character lands on cloud, cloud fades out. put in code determine when hit, there multiple clouds registered under same skspritenode, when lands on cloud, wrong cloud fading away, added skspritenode being removed, not 1 colliding with.
is there way removes 1 character has collided with, not earliest 1 spawns? here code:
func didbegincontact(contact: skphysicscontact) { let contactmask = contact.bodya.categorybitmask | contact.bodyb.categorybitmask switch(contactmask) { case bodytype.personcategory.rawvalue | bodytype.cloudcategory.rawvalue: let checkdelay = delay(0.02) { self.cloud.runaction(self.fadeaway) } default: return person.physicsbody?.usesprecisecollisiondetection = true person.size = cgsizemake(self.frame.size.width / 25, self.frame.size.height / 16.25) person.physicsbody = skphysicsbody(rectangleofsize: person.size) person.physicsbody?.restitution = 0 person.physicsbody?.friction = 0 person.physicsbody?.allowsrotation = false person.physicsbody?.affectedbygravity = true person.physicsbody?.dynamic = true person.physicsbody?.lineardamping = 0 person.zposition = 5 person.physicsbody?.categorybitmask = bodytype.personcategory.rawvalue person.physicsbody?.contacttestbitmask = bodytype.cloudcategory.rawvalue person.position = cgpoint(x: cgrectgetmidx(self.frame), y: cgrectgetmidy(self.frame) * 1.7) self.addchild(person) cloud = skspritenode(texture: normalcloudtexture) cloud.zposition = 7 cloud.physicsbody?.usesprecisecollisiondetection = true cloud.physicsbody?.affectedbygravity = false cloud.physicsbody?.allowsrotation = false cloud.size = cgsizemake(self.frame.size.width / 8.05, self.frame.size.height / 40) cloud.physicsbody = skphysicsbody(rectangleofsize: cloud.size) cloud.physicsbody?.friction = 0 cloud.physicsbody?.restitution = 0 cloud.physicsbody?.dynamic = false cloud.position = cgpointmake(cgrectgetmidx(self.frame), cgrectgetmidy(self.frame) / 7.60) addchild(cloud)
you need remove cloud represented physicsbody making contact. bodya either player, or cloud, , bodyb either player or cloud. actual skspritenode physics body. can referenced via node property on skphysics body. either bodya.node, or bodyb.node.
Comments
Post a Comment