[英]Background images flickering in a SpriteKit app using Swift
我在Sprite Kit应用中有几层背景,中层,前景,地面等。
我设法使它们循环播放,但是麻烦的是,当它们加载时,它们会闪烁,并且不能从一个图像平稳过渡到另一个图像。
我也有一个问题,图像之间出现间隙,但是可以通过在每个图像的宽度上增加一个像素来解决。
闪烁并非每次都会发生,并且会循环出现,并且与图像的大小(以帧或视图方式),从宽度中删除多余的像素,更改速度,更改设备,等等
同样,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)
此处列出的所有层也都相同,而且速度等似乎都不会使它变好或变差。
任何帮助将不胜感激。
谢谢,
史蒂芬
我是否正确,您想要背景不断变化的速度?
我认为,当在同一位置有两个图像时会发生闪烁,但编程人员不知道哪个图像需要打开,因此彼此交替显示。
PS。 这是一个答案,因为我无法发表评论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.