有人请分享当前的SpriteKit纹理图集样本以将其拉开

问题描述 投票:0回答:1

我的背景是Arduino,我发现Swift有点不透明。也有很多过时的教程。通过将某些东西拆开,我学得最好,所以我正在努力让屏幕上显示一个动画精灵。我将使用一个小的动画.png序列,将其保存到ball.atlas文件夹中并将其复制到Assets.xcassets。

我发现我相信Knight0fDragon发布的内容。运行它会在控制台中显示“有效”,但是我不明白如何将其分配给玩家,这样才能在模拟器上显示出来。如果有人愿意共享所需的其他代码,我可以将其拆开。

这里是代码:

    let textureAtlas = SKTextureAtlas(named: "example")
    var textureArray = [SKTexture]()
    var frames:[SKTexture] = []
    for index in 1 ... 59 {
        let textureName = "example_\(index)"
        let texture = textureAtlas.textureNamed(textureName)
        frames.append(texture)
        textureArray = frames
        print("worked")
animation sprite-kit textures
1个回答
0
投票
我无法与您共享纹理图集,但请您帮忙解释一下,见下文

let textureAtlas = SKTextureAtlas(named: "example") var textureArray = [SKTexture]() var frames:[SKTexture] = [] for index in 1 ... 59 { let textureName = "example_\(index)" let texture = textureAtlas.textureNamed(textureName) frames.append(texture) textureArray = frames print("worked")

提供“ let textureName =” example_(index)“的行是KoD为您提供Atlas中所有子画面的命名约定的地方。这部分代码的Atlas本身称为” example“。保存了所有子画面在Atlas中指定以下名称“ example_X”(X为整数),例如example_1,example_2,example_3等...直到获得example_59。如果不想制作59个纹理,则需要编辑for循环给出新值。
© www.soinside.com 2019 - 2024. All rights reserved.