ios - Swift Spritekit Scrolling Background -


i trying find best method vertically scrolling background in swift, without using update method. background 1 image should loop infinite. image should in middle of screen (full-size), moving down, , on top of image should image spawned.

however, mine doesn't work quite right, spawns 2 images, , after delay pop , start actions again. also, breaks down 30 fps 26, want avoid. hope somebody, more swift can me.

let background = sktexture(imagenamed: "background.png")     background.filteringmode = .nearest      let backgroundmove = skaction.movebyx(0, y: -self.frame.size.height, duration: 10)     let backgroundreset = skaction.movebyx(0, y: self.frame.size.height, duration: 0.0)     let backgroundmoveandresetforever = skaction.repeatactionforever(skaction.sequence([backgroundmove,backgroundreset]))      var i:cgfloat = 0; < 2.0 + self.frame.size.height / (background.size().height * 2); ++i {         let sprite = skspritenode(texture: background)         sprite.size = cgsize(width: self.frame.size.width / 2, height: self.frame.size.height)         sprite.position = cgpointmake(self.frame.size.width / 2, self.frame.size.height / 2 * i)         sprite.zposition = 1         sprite.runaction(backgroundmoveandresetforever)         self.addchild(sprite)     } 

this code used make background moves right left across screen. used loop generate 3 backgrounds, of formed line passed through screen , returned original position when done. convert screen moves top bottom, have replace movebyx skactions movetoy, , exchange changing x values changing y values. hope helps!

func makebackground() {      var backgroundtexture = sktexture(imagenamed: "img/bg.png")      //move background right left; replace     var shiftbackground = skaction.movebyx(-backgroundtexture.size().width, y: 0, duration: 9)     var replacebackground = skaction.movebyx(backgroundtexture.size().width, y:0, duration: 0)     var movingandreplacingbackground = skaction.repeatactionforever(skaction.sequence([shiftbackground,replacebackground]))      var i:cgfloat = 0; i<3; i++ {         //defining background; giving height , moving width         background=skspritenode(texture:backgroundtexture)         background.position = cgpoint(x: backgroundtexture.size().width/2 + (backgroundtexture.size().width * i), y: cgrectgetmidy(self.frame))         background.size.height = self.frame.height         background.runaction(movingandreplacingbackground)          self.addchild(background)     } } 

Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -