- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我希望我的 SpriteKit
游戏不会中断用户收听的背景音乐(Music.app 或广播应用)。
一切顺利,直到执行到这一行:
sSharedShootSoundAction = [SKAction playSoundFileNamed:@"plane_shoot.aiff"
waitForCompletion:NO];
此行后背景音乐停止。如何避免这种情况?
最佳答案
我自己也遇到过这个问题。仅供引用,我的解决方案很快,所以如果您仍在使用它,只需将其转换为 Objective C。
对我来说,我的解决方案包括两个部分。首先,我必须在场景文件中的 didMoveToView 函数中初始化 SoundAction SKAction。所以你的场景文件应该是这样的:
import SpriteKit
import GameKit
import AVFoundation
class GameScene: SKScene, SKPhysicsContactDelegate {
var sSharedShootSoundAction: SKAction = SKAction()
override func didMoveToView(view: SKView) {
/* Setup your scene here */
sSharedShootSoundAction = SKAction.playSoundFileNamed("plane_shoot.aiff", waitForCompletion: false)
}
}
然后在您的 AppDelegate 文件中,您需要将以下代码行放入应用程序的 didFinishLaunchingWithOptions 函数中。 (不要忘记在您的 APPDELEGATE 中导入 AVFOUNDATION)。所以你的应用委托(delegate)方法应该像这样:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
// INSERT THIS LINE BELOW.
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient, error: nil)
return true
}
希望这能像对我一样为您解决问题!如果没有,请告诉我。
关于ios - SKAction playSoundFileNamed 停止背景音乐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21835402/
我正在尝试使用 SKAction 播放 aiff 文件。此代码导致 白噪声在模拟器和我的 iPod 上播放: SKAction *sound = [SKAction playSoundFileName
我有几个关卡都使用相同的音效。我没有在每个级别都使用相同的代码,而是将所有声音合并到一个单例类中。但是,当我从其他类运行该方法时,将其置于单例中不会播放任何声音。我没有错误或警告。 当我在每个类中使用
我正在使用这段代码为我的游戏关卡添加背景音乐 [self runAction:[SKAction playSoundFileNamed:@"dasdas.mp3" waitForCompletion:
我一直在使用 playSoundFileNamed() 来播放机关枪类型的声音 - 重复得非常快,并且经常有声音重叠。我想给它添加一个音量控制,但我不知道该怎么做——因为它需要不同数量的音效相互播放,
我想同时播放多个声音。我这样使用SpriteKit SKAction: SKAction.playSoundFileNamed("aa.wav", waitForCompletion: true) 我
我希望我的 SpriteKit 游戏不会中断用户收听的背景音乐(Music.app 或广播应用)。 一切顺利,直到执行到这一行: sSharedShootSoundAction = [SKAction
我正在使用 runAction(SKAction.playSoundFileNamed() 在我的游戏中添加音效。但是 Xcode 在这一点上发现了一个问题。播放声音时,屏幕滞后。我使用 self.r
我在使用受控定时器间隔发射大约 80 次激光后出现此错误,因此它每 0.2 秒发射一次。 * 由于未捕获的异常“加载资源失败”而终止应用程序,原因:“无法加载资源 squish.mp3”* 首先抛出调
我想弄清楚为什么 playSoundFileNamed 在接到两个连续的电话后不起作用。实际上,它仅在接到第一个电话后才起作用。复制步骤是: 开始游戏 等一个电话,然后转到后台 电话通话结束(来电者拒
无论我尝试在项目中播放什么 wav 文件,我都会收到相同的错误。错误状态:由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“无法加载资源 namedfil
好吧,这个让我觉得自己像个彻头彻尾的白痴。 我的游戏中有一种方法,旨在通过一次弹出一个字母来为文本框中的文本设置动画。在我的 DDTextBox 类中,有一个名为 animateText 的动画方法。
注意: 已经几天了,我仍然遇到这个问题。有一件事会有所帮助,那就是了解一些可以尝试的故障排除想法,这样我就可以找出导致崩溃的原因。任何能引导我走向正确方向的帮助将不胜感激。 我在模拟器以及多个不同的
有没有办法调节通过 SKAction 播放的声音的音量 playSoundFileNamed:waitForCompletion: . 我想在我的游戏中实现一个简单的音乐和音效 slider 。我可以
有人在使用 iOS Sprite Kit 通过 iOS 设备的外部扬声器通过 SKAction playSoundFileNamed 播放音频时遇到过问题吗?我有以下代码可以通过耳机毫无问题地播放 M
我的游戏基本完成了。检查 Xcode 中的泄漏。发现我每次玩游戏都会泄漏大约 0.3 MB。然后去了仪器并查看了持久数据。 罪魁祸首 1: SKTexture,被调用了很多但没有持续增长 罪魁祸首 2
我正在尝试制作一个按钮,按下时会播放声音,再次按下时声音会停止。我正在使用 playSoundFileNamed: runAction: withKey: 和 removeActionForKey,但
我对 SpriteKit SKAction.playSoundFileNamed 有疑问。实际上,在正确播放一段时间后,应用程序崩溃并表示无法加载。该文件包含在捆绑导入中,项目文件存在并且一切都已正确
在我的应用程序中,我需要使用很多简短的不同 mp3(大约 500 个项目逐一) 所以我使用SKAction playSoundFileNamed 大约 200 声声音后,它崩溃并显示“无法加载资源 -
我在应用程序的崩溃日志中看到少量 SpriteKit playSoundFileNamed 崩溃。崩溃发生在 iOS 8.3 上。 0 CoreFoundation __exceptionPrepro
我现在已经遇到过无数次了。客户发给我一些 .mp3 放在项目中。当我尝试使用此代码播放它们时: SKAction *play = [SKAction playSoundFileNamed:@"bird
我是一名优秀的程序员,十分优秀!