gpt4 book ai didi

swift - SpriteNode 动画失败

转载 作者:行者123 更新时间:2023-11-28 06:30:55 25 4
gpt4 key购买 nike

我一直在尝试让 Sprite 具有不止一种纹理,这样它看起来就像在移动一样。我正在查看其他问题,但他们所做的一切都没有解决我的问题,这是我的代码:

    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))

当我运行模拟时, Sprite 与“peng_0”纹理保持静止,但我希望它每 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)

关于swift - SpriteNode 动画失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40369712/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com