Ios 使用Swift的SpriteKit应用程序中闪烁的背景图像
我有几层背景,中间,前景,地面等在一个精灵工具包应用程序 我已经设法让它们循环,但问题是,当它们加载时,它们会闪烁,不能从一个图像平稳过渡到另一个图像 我也有一个问题,图像之间出现的差距,但这是解决了增加一个额外的像素的宽度每个 闪烁并不是每次都会发生,它会循环,似乎与图像的大小(帧或视图)、从宽度中移除额外像素、更改速度、更改设备等没有任何关系 此外,Z位置正常,并且游戏视图控制器中的忽略兄弟顺序对解决该问题没有影响 有人知道为什么会这样吗?我的代码中是否有我做错的地方,或者其他人是否也有类似的体验?我在其他地方找不到确切的比较 以下是受影响的代码示例: 在viewDidLoad中:Ios 使用Swift的SpriteKit应用程序中闪烁的背景图像,ios,sprite-kit,skspritenode,Ios,Sprite Kit,Skspritenode,我有几层背景,中间,前景,地面等在一个精灵工具包应用程序 我已经设法让它们循环,但问题是,当它们加载时,它们会闪烁,不能从一个图像平稳过渡到另一个图像 我也有一个问题,图像之间出现的差距,但这是解决了增加一个额外的像素的宽度每个 闪烁并不是每次都会发生,它会循环,似乎与图像的大小(帧或视图)、从宽度中移除额外像素、更改速度、更改设备等没有任何关系 此外,Z位置正常,并且游戏视图控制器中的忽略兄弟顺序对解决该问题没有影响 有人知道为什么会这样吗?我的代码中是否有我做错的地方,或者其他人是否也有类似
//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)
这对于这里列出的所有层也是一样的,速度等似乎不会使它变得更好或更糟
任何帮助都将不胜感激
谢谢
史蒂文:你想要一个速度不一样、无休止移动的背景,我说得对吗 我认为闪烁发生在同一个地方有两个图像时,但编程不知道需要打开哪个,所以交替使用
注:这是一个答案,因为我无法评论。但你想让它左右移动还是只是一个不断移动的背景?在一个平滑的循环中不断移动,在一定数量的循环后改变速度,但完全平滑,没有闪烁。如果你的背景运行平稳,但只是不时闪烁。试着为每一块背景加上另一个z,这样程序就知道上面是什么了。进一步休息我帮不了你self.frame.size.height-self.frame.size.height你知道这没什么用吗?不,事实上,它应该没有说明高度吗?