xcode - Score var updates double randomly -
i'm making game, , i'm working on scoring system. however, i'm facing stupid problem. score var when called increase value unary operator (+=) 1, updates value 2 points, instead of 1, , it's doing randomly. have written protocol, i'm conforming gamescene class, , i'm calling method when there contact between sprites.
func wascollected(item: gold) { score += item.pointvalue } could method called twice instead of once? because in console see numbers update sequentially 2 when try collect single point @ random moments. i've tried fix using score++ instead of accessing item.pointvalue property, problem still exists.
here method i'm calling while setting text property in custom class , according breakpoint i'm getting character twice single execution of method. i'm doing wrong? i'm doing method, have bitmap graphics i'm using font numbers.
var i:nsinteger = 0; < text.length; i++ { //get character in text current position in loop //getting scalar encoded value let scalarencoded:unichar = text.characteratindex(i) //decoding scalar let scalardecoded = character(unicodescalar(scalarencoded)) //build texture name character , font name let texturename:nsstring = "\(fontname)\(scalardecoded)" print(texturename) if < children.count { //reuse existing node letter = children[i] as! skspritenode letter.texture = graphicsatlas.texturenamed(texturename string) letter.size = letter.texture!.size() } else { //create new node if not exist letter = skspritenode(texture: graphicsatlas.texturenamed(texturename string)) letter.anchorpoint = cgpointzero self.addchild(letter) } letter.position = pos pos.x += letter.size.width + letterspacing totalsize.width = letter.size.width + letterspacing if totalsize.height < letter.size.height { totalsize.height = letter.size.height } }
Comments
Post a Comment