1
在Sprite Kit应用程序中,我有几层背景,中景,前景,地面等。使用Swift在SpriteKit应用程序中闪烁的背景图像
我已经设法让他们循环,但麻烦的是,当他们加载时,他们闪烁并且不会平稳地从一个图像过渡到另一个。
我也有一个问题与图像之间出现的差距,但这是通过增加一个额外的像素的宽度来解决。
闪烁不会每次都发生,它会循环,看起来没有任何关系,如何调整图像的大小(框架或查看),从宽度中删除多余的像素,改变速度,更改设备等。
此外,Z位置可以,游戏视图控制器中的忽略兄弟顺序不会影响解析它。
有没有人知道为什么会发生这种情况?我的代码中是否有任何错误,或者其他人遇到与SpriteKit类似的问题?我无法在其他地方找到确切的比较结果。
这是影响我的代码示例:
在viewDidLoad中:
//Declaration of the midground nodes.
var mgImage: SKSpriteNode = SKSpriteNode()
var mgImage2: SKSpriteNode = SKSpriteNode()
在didMoveToView:
//Creates an instance of both sprites that are of the same image that are to be lined up against each other in the x axis creating the illution of continuity.
mgImage = SKSpriteNode(imageNamed: "CityMid.png")
mgImage2 = SKSpriteNode(imageNamed: "CityMid.png")
//Specifies the Z position of the images.
mgImage.zPosition = 1
mgImage2.zPosition = 1
//Scales the image to the correct size of the screen.
mgImage.size.width = self.frame.width + 1
mgImage.size.height = self.frame.height
mgImage2.size.width = self.frame.width + 1
mgImage2.size.height = self.frame.height
//Specicies the x position of the images. By offsetting the second you create the illution of a long, continuous image.
mgImage.position.x = view.bounds.size.width * 0.5
mgImage2.position.x = view.bounds.size.width * 1.5
//Specifies the y postion of the images, obviously these are the same as they are not to be offset at any time.
mgImage.position.y = (self.frame.size.height - self.frame.size.height) + self.mgImage.size.height/2
mgImage2.position.y = (self.frame.size.height - self.frame.size.height) + self.mgImage2.size.height/2
//Prevents aliasing with other nearby spites.
mgImage.texture?.filteringMode = SKTextureFilteringMode.Nearest
mgImage2.texture?.filteringMode = SKTextureFilteringMode.Nearest
//Adds instances of the sprites to the scene.
self.addChild(mgImage)
self.addChild(mgImage2)
这也是所有层相同的是被列入一次又一次,速度等似乎并没有使它变得更好或更糟。
任何帮助将不胜感激。
感谢,
史蒂芬
这听起来是正确的。我如何解决这个问题? – Fiducial13
但是你想让它左右移动,还是只是无限移动的背景? – Cing
无尽地移动在一个平滑的循环中,在一定数量的循环后改变速度,但完全平滑而没有闪烁。 – Fiducial13