2017-07-27 80 views
0

我试图做一个主要用户动画的游戏,我将gif转换为png,并将每个帧都放入一个文件夹中。但是,现在我只是试图让第一帧出现,但没有出现。对不起,如果我说这个怪异,我的英语不是很好。 enter image description hereSpritekit动画不工作

现在我认为只是第一帧“trumpyhappy1.png”应该显示,当我尝试运行它,但是当我运行它时什么也没有显示出来。

+0

发布代码时,请使用代码标签,而不是张贴图片......无论如何,请检查您的人是否在屏幕外。打印'view.size'和'scene.size'(你也可以添加'guy.size'),看看是否一切正常。或者,像下面的答案中指出的那样,可能发生的情况是,您在“GameViewController”中呈现错误的场景。 – Whirlwind

回答

0

所以基本上在spritekit动画一个spritenode你应该做这个

override func didMove() { 
    let mainGuy = SKSpriteNode() 

    self.addChild(mainGuy) 

    // Give your size and position and everything 
    // Then to animate that spriteNode with frames 

    let textureAtlas = SKTextureAtlas(named: "trump") 
    let frames: [SKTexture] = [] 

    for i in 0...textureAtlas.textureNames.count { 
     var name = "trumphappy\(i).png" 
     frames.append(SKTexture(named: name)) 
    } 


    // Then to create the animation add this code 

    let animation = SKAction.animate(with: frames, timePerFrame:) // Whatever time you want your animation to spend on each frame 
} 

这应该工作,希望工程!

+0

感谢您的回应,但它仍然无法正常工作。当我运行它模拟器是空白的,并没有显示任何东西。 – at26

+0

是否将您的场景添加到视图控制器? –

+0

尝试将图像添加到xc资源 –