ios - How to increase performance in swift 2.0? -


hi im new swift , game random generated square fall down @ random speed, im having trouble function (this function executed when user touch square):

let font = uifont(name: "avenir next medium", size: 16) let bgmusicurl:nsurl = nsbundle.mainbundle().urlforresource("destroy-square", withextension: "mp3")!  override func didmovetoview(view: skview) {     {         try  squaredestroyedsound =  avaudioplayer(contentsofurl: bgmusicurl, filetypehint: nil) }     catch _{         return print("no sound file")     } squaredestroyedsound.preparetoplay() }       func squareexploded (pos: cgpoint, nodecolor: string, points: string) {         let mylabel = sklabelnode(fontnamed: font?.fontname)         let emitternode = skemitternode(filenamed: "explodedwhitesquare.sks")         mylabel.fontsize = 20         mylabel.text = points         mylabel.position = pos         actionmovepoint = skaction.movetoy(pos.y + 200, duration: 0.8)         self.addchild(mylabel)         mylabel.runaction(skaction.sequence([actionmovepoint, actionmovedonepoint]))         emitternode!.particlecolorsequence = nil         emitternode!.particlecolorblendfactor = 1.0         emitternode!.particlecolor = uicolor(rgba: nodecolor)         emitternode!.particleposition = pos         self.addchild(emitternode!)         emitternode!.runaction(skaction.waitforduration(2), completion: { emitternode!.removefromparent() })         squaredestroyedsound.play()     } 

this function need 3 things @ same time :

1- mylabel text go touched square position 0.8 second , should removed.

2- emitternode spark effect create it, effect square position , color produce effect have same color touched square, duration effect 2 seconds , removed.

3- bgmusicurl/squaredestroyedsound url path sound each square touched , it's played when time

my problem when user touche square game lag little bit screen freeze , fps drop 60 55/52. function work fine if don't use function game don't lag more no fps drop need there way optimize code ?

i use skaction sequence perform of operations , avoid use of avaudioplayer -

func squareexploded (pos: cgpoint, nodecolor: string, points: string) {     let mylabel = sklabelnode(fontnamed: font?.fontname)     let emitternode = skemitternode(filenamed: "explodedwhitesquare.sks")     mylabel.fontsize = 20     mylabel.text = points     mylabel.position = pos     actionmovepoint = skaction.movetoy(pos.y + 200, duration: 0.8)     self.addchild(mylabel)     mylabel.runaction(skaction.sequence([actionmovepoint, actionmovedonepoint]))     emitternode!.particlecolorsequence = nil     emitternode!.particlecolorblendfactor = 1.0     emitternode!.particlecolor = uicolor(rgba: nodecolor)     emitternode!.particleposition = pos     self.addchild(emitternode!)     let actionsequence=skaction.sequence([skaction.playsoundfilenamed("destroy-square.mp3", waitforcompletion: false), skaction.waitforduration(2),skaction.removefromparent()])     emitternode!.runaction(actionsequence) } 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -