ios - Swift: Progress bar jumps when using showing progress -


the code below works if background , progress bar share same dimensions. if progress bar shorter, bar jumps around bit whenever there update -- if scaling progress bar changes origin progress bar.

what's right way implement custom progress bars in swift , spritekit?

private func initprogresslayer(gridleftx: cgfloat, gridwidth: cgfloat) {     // set progress bar width     var progresswidth = gridwidth     let barwidth = cgfloat(50)     let barheight = progressbarheight      // set layer position     let posy = statslayer.position.y - cgfloat(progressbarheight/2)     let posx = cgfloat(0.0) - cgfloat(progresswidth/2)     progresslayer.position = cgpoint(x: posx, y: posy)      // create background progress bar     let backgroundrect = cgrect(x: 0, y: 0, width: progresswidth, height: progressbarheight)     let background = skshapenode(rect: backgroundrect)     background.fillcolor = progressbackgroundcolor      // create progress bar     let barrect = cgrect(x: 10, y: 0, width: barwidth, height: barheight)     progressbar = skshapenode(rect: barrect)     progressbar.fillcolor = progressbarcolor      // add background , progress bar layer     progresslayer.addchild(background)     progresslayer.addchild(progressbar) }   private func updateprogress(var progress: cgfloat) {     if (progress > 1.0) {         progress = 1.0     }     let scaleaction = skaction.scalexto(progress, duration: nstimeinterval(0.3))     scaleaction.timingmode = .easein     progressbar.runaction(scaleaction) } 

check following:

  • is updateprogress: being called background thread? (it shouldn't)
  • how updateprogress: called? if enough might want remove scalex animation , apply scale directly sprite. in fact, might want try doing anyway, it's might causing issues.
  • have shifted anchorpoint of progress bar sprite? create random behaviours when try , edit frame properties.

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -