Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios SKAction.animate使用SKTextureAtlas方法不设置动画_Ios_Swift_Animation_Sprite Kit_Subclass - Fatal编程技术网

Ios SKAction.animate使用SKTextureAtlas方法不设置动画

Ios SKAction.animate使用SKTextureAtlas方法不设置动画,ios,swift,animation,sprite-kit,subclass,Ios,Swift,Animation,Sprite Kit,Subclass,SKAction.animate方法未正确设置动画如何使其正常工作 示例动画方法: let textureAtlas = SKTextureAtlas(named: "example") var textureArray = [SKTexture]() var frames:[SKTexture] = [] for index in 1 ... 4 { let textureName = "example_\(index)" let textu

SKAction.animate方法未正确设置动画如何使其正常工作

示例动画方法:

   let textureAtlas = SKTextureAtlas(named: "example")
   var textureArray = [SKTexture]()
   var frames:[SKTexture] = []
   for index in 1 ... 4 {
       let textureName = "example_\(index)"
       let texture = textureAtlas.textureNamed(textureName)
       frames.append(texture)
       textureArray = frames
       print("worked")
   }
   let animate = SKAction.animate(with: textureArray, timePerFrame: 0.01)
   let forever = SKAction.repeatForever(animate)
   self.run(forever)
它的打印“工作”,但在我的场景中,它显示了当SpriteKit找不到请求的图像时得到的红色X图像。有什么我做错了吗


提前谢谢

不要为此使用SKTextureAtlas

尝试:

Swift 3:

    var textureArray = [SKTexture]()
    for index in 1 ... 4 {
        let textureName = "example_\(index)"
        let texture = SKTexture(imageNamed: textureName)
        textureArray.append(texture)
    }
    let animate = SKAction.animate(with: textureArray, timePerFrame: 0.01)
    let forever = SKAction.repeatForever(animate)
    self.run(forever)

不要为此使用SKTextureAtlas

尝试:

Swift 3:

    var textureArray = [SKTexture]()
    for index in 1 ... 4 {
        let textureName = "example_\(index)"
        let texture = SKTexture(imageNamed: textureName)
        textureArray.append(texture)
    }
    let animate = SKAction.animate(with: textureArray, timePerFrame: 0.01)
    let forever = SKAction.repeatForever(animate)
    self.run(forever)

红色X表示纹理图集未正确设置,请检查xcassets文件夹以确保纹理已设置

它应该是这样的:


红色X表示纹理图集设置不正确,请检查xcassets文件夹以确保纹理设置正确

它应该是这样的:



这是个糟糕的建议,他们应该修复纹理图谱并加以利用。纹理地图集旨在减少应用程序的内存足迹。@Knight0fDragon我不同意,你能上传一个示例吗?是的,请!这不是自我挑战。我记得在尝试从atlas制作动画时失败了=/那可能是因为你没有正确使用地图册。如果你用我的xcatlas设置来设置OP代码,你会看到它在工作。这是一个错误的建议,他们应该修复他们的纹理图集并利用它。纹理地图集旨在减少应用程序的内存足迹。@Knight0fDragon我不同意,你能上传一个示例吗?是的,请!这不是自我挑战。我记得在尝试从atlas制作动画时失败了=/那可能是因为你没有正确使用地图册。如果你用我的xcatlas设置来设置操作代码,你会看到它在工作。我以为textureAtlas应该在侧视图文件中,access thingyTexture atlas会把你所有的小纹理都变成一个大纹理。我喜欢称之为超级纹理我刚意识到你说的。你的意思是在项目视图中。不,这是在XCAssets中引入它之前的老方法所以你说如果我将我的SKTextureAtlases移到XCAssets文件夹中会更有效?是的,你现在的做法是老方法,通过XCAssets,你可以获得额外的元信息,你可以给你的纹理更好地定义itI,我认为textureAtlas应该在侧视图文件中,access thingyTexture atlas会将你所有的小纹理转化为一个巨大的纹理。我喜欢称之为超级纹理我刚意识到你说的。你的意思是在项目视图中。不,这是在XCAssets中引入之前的老方法,所以你说如果我将我的SKTextureAtlases移动到XCAssets文件夹中会更有效?是的,你现在这样做的方式是老方法,通过XCAssets获得额外的元信息,你可以给你的纹理更好地定义它