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