hi
I want to play first background music and when it ends, start second music in loop.
For achieving this, I checked if background music is ended by a schedule.
The problem is if I play first music, and then replace the scene, the schedule will not fire and second music not plays.
How can i play first background music and when it ends, start second music in loop? (scene replacement may occur)
Hacking CocosDenshion add a callback when BGM ends up is much better.
If you want to keep this schedule, You can create a global CCNode, add schedule in it, DON’T add this node into any other nodes. It will work as you wish.
The source code below hasn’t been compiled and tested.
class MyObject : public CCObject
{
void checkBGMusicPlaying(float dt)
{
// blabla
}
MyObject()
{
CCDirector::sharedDirector()->getSheduler()->scheduleSelector(schedule_selector(MyObject::checkBGMusicPlaying), this, 0, false);
}
};
// Use it as a global variable
MyObject g_BGMusicListener;
We can do this because the minimal for CCScheduler is CCObject. I said CCNode in the previous post, but now I check the source code, CCObject is enough.
What you want is just a timer callback from CCScheduler.