Skaction.playsoundfilenamed 重复时崩溃 - sprite kit [英] Skaction.playsoundfilenamed crashes when repeat - sprite kit

查看:22
本文介绍了Skaction.playsoundfilenamed 重复时崩溃 - sprite kit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对精灵套件 SKAction.playSoundFileNamed 有疑问.实际上,在正确播放一段时间后,应用程序崩溃说它不会加载.该文件包含在包导入中,项目文件存在并且一切都已正确设置.

I have a problem with sprite kit SKAction.playSoundFileNamed. In practice, after some time it is played correctly , the app crashes saying it will not load . The file is included in the bundle import the project file exists and everything is properly set.

唯一的问题,玩了一段时间后,我会崩溃说找不到文件,或者至少无法加载.

The only problem , after some time I play, I will crash saying it can not find the file , or at least can not be loaded .

我的问题是,有没有办法在每次播放SKAction.playSoundFileNamed的声音时充电?

My question is , is there a way to recharge every time the sound SKAction.playSoundFileNamed ?

编辑 - 已解决

//init
var sound = SKAction.playSoundFileNamed("sound.mp3", waitForCompletion: false)
var sound2 = SKAction.playSoundFileNamed("sound2.mp3", waitForCompletion: false) 

//in the code call function when play sound:
playSound(sound)

...

func playSound(soundVariable : SKAction)
{
    runAction(soundVariable)   
}

实例化的预加载声音不再产生崩溃

The preload sounds instantiated no longer generates crash

推荐答案

前置声音变量

//init
var sound = SKAction.playSoundFileNamed("sound.mp3", waitForCompletion: false)
var sound2 = SKAction.playSoundFileNamed("sound2.mp3", waitForCompletion: false) 

//in the code call function when play sound:
playSound(sound)

...

func playSound(soundVariable : SKAction)
{
    runAction(soundVariable)   
}

这篇关于Skaction.playsoundfilenamed 重复时崩溃 - sprite kit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆