i want make scrolling background when phone in portrait mode tried these codes didn't helped me in portrait mode
let background1 = skspritenode(imagenamed: "space") let background2 = skspritenode(imagenamed: "space")
in "didmovetoview" method
background1.size = cgsize(width: frame.width, height: frame.height) background1.anchorpoint = cgpointzero background1.position = cgpointmake(0, 0) background1.zposition = -15 self.addchild(background1) background2.size = cgsize(width: frame.width, height: frame.height) background2.anchorpoint = cgpointzero background2.position = cgpointmake(background1.size.width - 1,0) background2.zposition = -15 self.addchild(background2)
in "override func update method
background1.position = cgpointmake(background1.position.x-2, background1.position.y) background2.position = cgpointmake(background2.position.x-2, background2.position.y) if(background1.position.x < -background1.size.width) { background1.position = cgpointmake(background1.position.x + background2.size.width , background2.position.y) } if(background2.position.x < -background2.size.width) { background2.position = cgpointmake(background2.position.x + background1.size.height, background1.position.y) }
the problem when background scrolling there gap between backgrounds, appreciated
i this, x = (1,2), causing problem:
backgroundx.size = cgsize(width: frame.width, height: frame.height)
you setting background texture's size of scene's frame overwriting original size inherited texture's source , needs calculate new position correctly.