sprite kit - how to get access to all my enemy nodes at the same time -
i have 6 sprites of enemies in spritekit game. want have access of them "enemies" in order make them appear on scene in random order. tried this:
class gamescene: skscene { var redbox = skspritenode(imagenamed: "redbox") var greenbox = skspritenode(imagenamed: "greenbox") var bluebox = skspritenode(imagenamed: "bluebox") var magentabox = skspritenode(imagenamed: "magentabox") var cyanbox = skspritenode(imagenamed: "cyanbox") var yellowbox = skspritenode(imagenamed: "yellowbox") func randombox() -> skspritenode { let boxes = [redbox, greenbox, bluebox, magentabox, cyanbox, yellowbox] let count = boxes.count var randomone = int(arc4random_uniform(uint32(count))) var randombox = boxes[randomone] return randombox } var onebox: skspritenode = randombox() }
but in onebox xcode gives me error , says "missing parameter #1 in call".
how pick random node right way?
edit: code causing error:
class gamescene: skscene { //boxes var redbox = skspritenode(imagenamed: "redbox") var greenbox = skspritenode(imagenamed: "greenbox") var bluebox = skspritenode(imagenamed: "bluebox") var magentabox = skspritenode(imagenamed: "magentabox") var cyanbox = skspritenode(imagenamed: "cyanbox") var yellowbox = skspritenode(imagenamed: "yellowbox") var onebox:skspritenode! func randombox() -> skspritenode { let boxes = [redbox, greenbox, bluebox, magentabox, cyanbox, yellowbox] let count = boxes.count var randomone = int(arc4random_uniform(uint32(count))) var randombox = boxes[randomone] return randombox } //random y func random() -> cgfloat { return cgfloat(float(arc4random()) / 0xffffffff) } func random(#min: cgfloat, max: cgfloat) -> cgfloat { return random() * (max - min) + min } override func didmovetoview(view: skview) { /* setup scene here */ var onebox: skspritenode = randombox() func addupperboxes() { let middley = random(min: size.height/2, max: size.height - size.height/3) onebox.position = cgpoint(x: size.width + onebox.size.width/2, y: middley) addchild(onebox) let middleduration = random(min: cgfloat(1.5), max: cgfloat(2.5)) let middlemove = skaction.moveto(cgpoint(x: -onebox.size.width/2, y: middley), duration: nstimeinterval(middleduration)) let middlemovedone = skaction.removefromparent() onebox.runaction(skaction.sequence([middlemove, middlemovedone])) } runaction(skaction.repeatactionforever( skaction.sequence([ skaction.runblock(addupperboxes), skaction.waitforduration(0.5) ]) )) }
Comments
Post a Comment