我发现SKAction playSoundFileNamed在IOS 9:https://forums.developer.apple.com/thread/20014中有内存泄漏
他们建议使用SKAudioNode,但是这个例子很快,我在我的项目中使用了objective。
示例:
func testAudioNode() {
let audioNode = SKAudioNode(fileNamed: "LevelUp")
audioNode.autoplayLooped = false
self.addChild(audioNode)
let playAction = SKAction.play()
audioNode.runAction(playAction)
} 我试过的是:
-(void)testSound{
testSound = [SKAudioNode nodeWithFileNamed:@"test.wav"];
testSound.autoplayLooped = false;
[self addChild:testSound];
SKAction *playaction = [SKAction play];
[testSound runAction:playaction];
}它将坠毁到:
[self addChild:testSound];那么,我如何使它工作,什么是好的技术,播放声音只在IOS 9>和SKAction的旧版本?
谢谢!
发布于 2016-03-22 18:03:14
方法+ nodeWithFileNamed:通过从游戏的主包加载存档文件来创建一个新节点。所以你不能在这种情况下使用它。
尝试这样的方法(使用initWithFileNamed初始化程序):
#import "GameScene.h"
@interface GameScene()
@property (nonatomic, strong)SKAudioNode *testSound;
@end
@implementation GameScene
-(void)didMoveToView:(SKView *)view{
self.testSound = [[SKAudioNode alloc] initWithFileNamed:@"test.wav"];
self.testSound.autoplayLooped = false;
[self addChild:self.testSound];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[self.testSound runAction:[SKAction play]];
}
@endhttps://stackoverflow.com/questions/36161202
复制相似问题