ios - 声音一直循环

标签 ios ipad audio cocos2d-iphone

我已经实现了加载声音数组的方法:

-(void) soundSuper
{
    [soundEngine stopAllSounds];

    [soundEngine playSound:(1000+tag) sourceGroupId:1 pitch:1 pan:1 gain:1.0f loop:NO];
    NSLog(@"sound1 activated");

    [self schedule:@selector(playSecondSound) interval:2];
}

-(void) playSecondSound {
    [self unschedule:@selector(playSecondSound)];
    [soundEngine playSound:(1008+tag) sourceGroupId:1 pitch:1 pan:1 gain:1.0f loop:NO];
    NSLog(@"sound2 activated");
}

这里,它加载声音,然后在触摸按钮时播放。两声同时响起。 问题是,现在我想将声音加载到我的 initScene 中。我用这种方法得到了这个:

[self schedule:@selector(soundSuper) interval:2];

但问题是,当我进入时,声音会播放,但它一直循环。我不知道该怎么办,因为我已将其取消在 void Second Sound 方法上。有什么问题吗?

最佳答案

您是否认为您也应该取消安排“soundSuper”选择器,就像这样

-(void) soundSuper
{
    //HERE : you unschedule this selector too.
    [self unschedule:@selector(soundSuper)];

    [soundEngine stopAllSounds];

    [soundEngine playSound:(1000+tag) sourceGroupId:1 pitch:1 pan:1 gain:1.0f loop:NO];
    NSLog(@"sound1 activated");

    [self schedule:@selector(playSecondSound) interval:2];
}

关于ios - 声音一直循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15660047/

相关文章:

iPhone iOS 如何从相机胶卷图像中提取照片元数据和地理标记信息?

ios - 如何在 Flutter 应用程序上使用 iOS 显示本地通知?

ios - HTML标签打不开用safari调试ipad

audio - 婴儿哭声检测

audio - 需要帮助来运行 libjitsi 示例

javascript - 如何停止声音警报?

ios - SwiftUI 如果让内部 View

ios - [UIView(CALayer Delegate)drawLayer:inContext:崩溃

ios - Xcode 7 大小类问题?

iphone - 从多个表中过滤数据