我一直试图让一个带有多个纹理的精灵,使它看起来好像在移动。我正在查看其他问题,他们所做的一切都没有解决我的问题,这是我的代码:
var textures = [SKTexture]()
for x in 0...2 {
let texture = SKTexture(imageNamed: "peng_" + String(x))
textures.append(texture)
print("pen_" + String(x))
}
let pen = SKSpriteNode(imageNamed: "peng_0")
self.addChild(pen)
let action = SKAction.animate(withNormalTextures: textures, timePerFrame: 0.1, resize: false, restore: true)
pen.run(SKAction.repeatForever(action))
当我运行模拟时,精灵保持静止与" peng_0"纹理,但我希望它每0.1秒迭代其他纹理
有谁知道我做错了什么,谢谢。
答案 0 :(得分:1)
在这里你可以像这样设置你的代码
var array = ["R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8"]
var textures:[SKTexture] = []
for i in 0 ..< array.count{
let texture: SKTexture = SKTexture(imageNamed: array[i])
textures.insert(texture, at:i)
}
let pen = SKSpriteNode(imageNamed: "R1")
self.addChild(pen)
let animation = SKAction.animate(with: textures, timePerFrame: 8/60, resize: true , restore:false )
pen.run = SKAction.repeatForever(animation)