// 在init这个函数当中做一些初始化的事情 bool HelloWorld::init() { ////////////////////////////// // 先构造父级对象 if ( !CCLayer::init() ) { return false; } CCSize size=CCDirector::sharedDirector()->getWinSize(); CCMenuItemFont* item=CCMenuItemFont::create("click me",this,menu_selector(HelloWorld::menuCallback)); item->setPosition(ccp(size.width/2,size.height/2)); CCMenu* menu=CCMenu::create(item,NULL); menu->setPosition(CCPointZero); addChild(menu); SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic("background.mp3"); //SimpleAudioEngine::sharedEngine()->preloadEffect();
return true; } void HelloWorld::menuCallback(CCObject* pSender) { SimpleAudioEngine::sharedEngine()->playBackgroundMusic("background.mp3"); }