Music and effects at the same time in cocos2d-x 4

Hi,
I have been researching about audio and all the examples I could found are with SimpleAudioEngine which I believe is deprecated in last version in favor of AudioEngine.
I find it a bit confusing compared with SimpleAudioEngine where you simple created an audio instance (CocosDenshion::SimpleAudioEngine::getInstance()) and then operate on with playEffect() for instance.
With AudioEngine class as far as I can tell you don’t create any instance. There is no method such as getInstance() correct. So this is what I have:

#include "HelloWorldScene.h"
#include "AudioEngine.h"


USING_NS_CC;


Scene* HelloWorld::createScene()
{
    return HelloWorld::create();
}


bool HelloWorld::init()
{
    if ( !Scene::init() )
        return false;
       // The background music
	int audioId1 = AudioEngine::play2d("sapMix.mp3", true, 1.0f);
      
       // The effect
	AudioEngine::preload("laserSound.mp3");
	int audioId2 = AudioEngine::play2d("laserSound.mp3");

    return true;
};

I know this code is not much, but it’s better than nothing. So, is there another audio class that I should be using for effects? I am a bit lost right now.

thanks

No, there isn’t a separate method to call for “effects”. The way you’re using AudioEngine it is correct.

thanks, I found that “sapMix.mp3” it self was delayed so it was confusing me because I thought both audios couldn’t play at the same time. I did a schedule for the laser and it plays at the same time ok.
(I am still getting my head around how schedule work)

Have you tried other audio files incase it’s related to this file?

Yes, it was the file. Thanks

It’s happened to me before, did you use a different file type or just a different file?

just a different file.

Ah, it happens and it can be so annoying. I know there are many times when im like it cant be the file and spend ages trying other stuff first.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.