gpt4 book ai didi

swift - SKTextureAtlas 被第二个 SKTextureAtlas 的声明覆盖

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

每当我创建两个变量并将其定义为 SKTextureAtlas 类型时,它们都会互相重写。这是我最初创建的两个 SKTextureAtlas

class GameScene: SKScene {

var idle = true

var TextureAtlas = SKTextureAtlas()
var TextureAtlasIdle = SKTextureAtlas()

稍后在我的代码中,我为每个图集分配一个图像文件夹。如果我注释掉第二个图集,我的动画可以工作,但是当我定义两个图集(如下所示)时,我的动画会重叠并播放 cat_walk 中的帧,即使它被告知仅播放 cat_idle

    TextureAtlasIdle = SKTextureAtlas(named: "cat_idle")

for i in 1...TextureAtlasIdle.textureNames.count{

let Name = "\(i).png"
TextureArrayIdle.append(SKTexture (imageNamed: Name))
}

TextureAtlas = SKTextureAtlas(named: "cat_walk")

这就是我开始我的 cat_idle 动画的方式。我没有启动cat_walk动画

aN.run(SKAction.repeatForever(SKAction.animate(with:self.TextureArrayIdle, timePerFrame: 0.1)))

我试图找出为什么这行代码导致我的两个不同的动画重叠。

TextureAtlas = SKTextureAtlas(named: "cat_walk")

最佳答案

纹理图集是一种游戏的 Sprite 表。您的方法不适合访问游戏的图集图像。修改您的 for 循环,如下所示:

  for i in 0..< 8 {
let texture:SKTexture = TextureAtlasIdle.textureNamed(String(format: "%i", i+1))
TextureArrayIdle.insert(texture, at:i)
}

每次访问 atlas 文件夹时,请使用此 for 循环过程。我在 for 循环中使用了静态 8 数字,这将是你的 Sprite 数。有一个简单的游戏叫做Desert Run在 github 中。请查看此内容以获取更多说明。

注意:您的猫的图像命名必须以 1.png 开头如果你想运行for循环

关于swift - SKTextureAtlas 被第二个 SKTextureAtlas 的声明覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51036460/

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