【发布时间】:2021-05-17 01:17:22
【问题描述】:
我正在使用 SpriteKit 创建一个 RPGGameKit 来帮助我开发我的 iOS 游戏。现在我的播放器可以移动了,我添加了动画和音频系统。
我遇到了一个同步纹理和声音的问题。就像我的玩家走路时的一步。
let atlas = SKTextureAtlas(named: "Walk")
let textures = atlas.getTextures() // I created an extension that returns textures of atlas
let walkingAnimation = SKAction.animate(with: textures, timePerFrame: 1)
所以,walkingAnimation 将循环遍历纹理并每 1 秒更改一次。
现在,我想在纹理发生变化时播放行走的声音。
我查看了 SKAction 和 SpriteKit 文档,但没有针对此 SKAction 的回调。
如果您想尝试和我一起完成这项工作,或者您对如何做有想法,请发表评论。
谢谢:)
【问题讨论】:
-
类似下面的东西会起作用 - 让 sequence = SKAction.sequence([walkinganimation,playsound])。只是为了把握好时机。
-
我尝试使用组、序列,但声音播放一次,动画继续。我希望能够在每次帧变化时播放声音。
-
你的动画有多少帧?
-
这取决于动画但我想抽象这部分
标签: ios swift sprite-kit skaction