sprite kit - Swift: score increases by 2 and not 1 when contact is detected? -
alright, i'm keeping score in sprite kit game , score stored in variable named animalscount. here set variable , label node outputting to:
//score count in stats bar //animal score count animalscount = 0 animalscountlabel.text = "\(animalscount)" animalscountlabel.fontsize = 45 animalscountlabel.fontcolor = skcolor.blackcolor() animalscountlabel.position = cgpoint (x: 630, y: 40) addchild(animalscountlabel) i need animalscount increase 1 every time contact between 2 sprite nodes, chicken1 , savior, made. here have animalscount increasing collision detection:
func didbegincontact(contact: skphysicscontact) { //chicken1 if (contact.bodya.categorybitmask == collidertype.savior.rawvalue && contact.bodyb.categorybitmask == collidertype.chicken1.rawvalue ) { println("chicken1 contact made") chicken1.hidden = true chicken1.setscale(0) animalscount += 1 animalscountlabel.text = "\(animalscount)" } else if (contact.bodya.categorybitmask == collidertype.chicken1.rawvalue && contact.bodyb.categorybitmask == collidertype.savior.rawvalue) { println("chicken1 contact made") chicken1.hidden = true chicken1.setscale(0) } (i increase score when savior collides chicken1 because can't happen vice versa) is, label starts @ 0 , animalscount increase 2 every time savior collides chicken1.
i'm assuming because animalscount goes when savior begins contact chicken1 , when ends contact.
how can change animalscount goes when contact begins? or how else can make animalscount go 1 , not 2? have tried having animalscount increment 0.5 , got error message.
Comments
Post a Comment