zoukankan      html  css  js  c++  java
  • cocos2d 播放音乐

    #include "HelloWorldScene.h"
    #include "SimpleAudioEngine.h"  
    
    #define EFFECT_FILE   "effect1.wav"
    #define MUSIC_FILE    "background.mp3"
    
    USING_NS_CC;
    using namespace CocosDenshion;
    
    CCScene* HelloWorld::scene()
    {
        // 'scene' is an autorelease object
        CCScene *scene = CCScene::create();
    
        // 'layer' is an autorelease object
        HelloWorld *layer = HelloWorld::create();
    
        // add layer as a child to scene
        scene->addChild(layer);
    
        // return the scene
        return scene;
    }
    
    // on "init" you need to initialize your instance
    bool HelloWorld::init()
    {
        //////////////////////////////
        // 1. super init first
        if ( !CCLayer::init() )
        {
            return false;
        }
        SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic( MUSIC_FILE );
        SimpleAudioEngine::sharedEngine()->preloadEffect( EFFECT_FILE );
    
        SimpleAudioEngine::sharedEngine()->setEffectsVolume(0.5);
        SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0.5);
    
        CCLabelTTF *abelttf=CCLabelTTF::create("play","Moncao", 48);
        CCMenuItemLabel *item=CCMenuItemLabel::create(abelttf,this, menu_selector(HelloWorld::menuCallback));
        CCMenu *menu=CCMenu::create(item,NULL);
        menu->setPosition(ccp(100,100));
        this->addChild(menu);
        return true;
    }
    
    
    void HelloWorld::menuCallback(CCObject* pSender)
    {
        SimpleAudioEngine::sharedEngine()->playBackgroundMusic(MUSIC_FILE);
        //SimpleAudioEngine::sharedEngine()->playBackgroundMusic(MUSIC_FILE, true);
        //SimpleAudioEngine::sharedEngine()->stopBackgroundMusic();
        //SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
        //SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
        //SimpleAudioEngine::sharedEngine()->rewindBackgroundMusic();
        /*
        if (SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying())
        {
            CCLOG("background music is playing");
        }
        else
        {
            CCLOG("background music is not playing");
        }
        */
        m_nSoundId = SimpleAudioEngine::sharedEngine()->playEffect(EFFECT_FILE);
        //m_nSoundId = SimpleAudioEngine::sharedEngine()->playEffect(EFFECT_FILE, true);
        //SimpleAudioEngine::sharedEngine()->stopEffect(m_nSoundId);
        //SimpleAudioEngine::sharedEngine()->unloadEffect(EFFECT_FILE);
        //SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(SimpleAudioEngine::sharedEngine()->getBackgroundMusicVolume() + 0.1f);
        //SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(SimpleAudioEngine::sharedEngine()->getBackgroundMusicVolume() - 0.1f);
        //SimpleAudioEngine::sharedEngine()->setEffectsVolume(SimpleAudioEngine::sharedEngine()->getEffectsVolume() + 0.1f);
        //SimpleAudioEngine::sharedEngine()->setEffectsVolume(SimpleAudioEngine::sharedEngine()->getEffectsVolume() - 0.1f);
        //SimpleAudioEngine::sharedEngine()->pauseEffect(m_nSoundId);
        //SimpleAudioEngine::sharedEngine()->resumeEffect(m_nSoundId);
        //SimpleAudioEngine::sharedEngine()->pauseAllEffects();
        //SimpleAudioEngine::sharedEngine()->resumeAllEffects();
        //SimpleAudioEngine::sharedEngine()->stopAllEffects();
    }
  • 相关阅读:
    工作流-1
    net core体系-Xamarin-2概要(lignshi)
    net core体系-web应用程序-4asp.net core2.0 项目实战(CMS)-第二章 入门篇-快速入门ASP.NET Core看这篇就够了
    手机支持NFC
    net core体系-Standard-1概述
    运营-赵本山最近有点烦:二人转产业链滑铁卢 关联公司IPO预披露
    MSSql-1内部数据库版本号
    (JAVA保留小数问题,基础)Probability hdu2131
    (stripTrailingZeros)A == B hdu2054
    (reverse)Palindromes hdu2163
  • 原文地址:https://www.cnblogs.com/yufenghou/p/3990481.html
Copyright © 2011-2022 走看看