【发布时间】:2015-11-03 20:18:51
【问题描述】:
我在 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)
这对于这里列出的所有层也是一样的,速度等似乎并没有让它变得更好或更糟。
任何帮助将不胜感激。
谢谢,
史蒂文
【问题讨论】:
标签: ios sprite-kit skspritenode