Пример #1
0
        public CocosDenshionTest()
        {
            m_pItmeMenu = null;
            m_tBeginPos = new CCPoint(0, 0);
            m_nSoundId  = 0;

            string[] testItems =
            {
                "play background music",
                "stop background music",
                "pause background music",
                "resume background music",
                "rewind background music",
                "is background music playing",
                "play effect",
                "play effect repeatly",
                "stop effect",
                "unload effect",
                "add background music volume",
                "sub background music volume",
                "add effects volume",
                "sub effects volume"
            };

            // add menu items for tests
            m_pItmeMenu = CCMenu.menuWithItems(null);
            CCSize s = CCDirector.sharedDirector().getWinSize();

            m_nTestCount = testItems.Count <string>();

            for (int i = 0; i < m_nTestCount; ++i)
            {
                CCLabelTTF      label     = CCLabelTTF.labelWithString(testItems[i], "Arial", 24);
                CCMenuItemLabel pMenuItem = CCMenuItemLabel.itemWithLabel(label, this, new SEL_MenuHandler(menuCallback));

                m_pItmeMenu.addChild(pMenuItem, i + 10000);
                pMenuItem.position = new CCPoint(s.width / 2, (s.height - (i + 1) * LINE_SPACE));
            }

            m_pItmeMenu.contentSize = new CCSize(s.width, (m_nTestCount + 1) * LINE_SPACE);
            m_pItmeMenu.position    = new CCPoint(0, 0);
            addChild(m_pItmeMenu);

            this.isTouchEnabled = true;

            // preload background music and effect
            SimpleAudioEngine.sharedEngine().preloadBackgroundMusic(CCFileUtils.fullPathFromRelativePath(MUSIC_FILE));
            SimpleAudioEngine.sharedEngine().preloadEffect(CCFileUtils.fullPathFromRelativePath(EFFECT_FILE));

            // set default volume
            SimpleAudioEngine.sharedEngine().setEffectsVolume(0.5f);
            SimpleAudioEngine.sharedEngine().setBackgroundMusicVolume(0.5f);
        }
Пример #2
0
        public void menuCallback(CCObject pSender)
        {
            // get the userdata, it's the index of the menu item clicked
            CCMenuItem pMenuItem = (CCMenuItem)(pSender);
            int        nIdx      = pMenuItem.zOrder - 10000;

            switch (nIdx)
            {
            // play background music
            case 0:

                SimpleAudioEngine.sharedEngine().playBackgroundMusic(CCFileUtils.fullPathFromRelativePath(MUSIC_FILE), true);
                break;

            // stop background music
            case 1:
                SimpleAudioEngine.sharedEngine().stopBackgroundMusic();
                break;

            // pause background music
            case 2:
                SimpleAudioEngine.sharedEngine().pauseBackgroundMusic();
                break;

            // resume background music
            case 3:
                SimpleAudioEngine.sharedEngine().resumeBackgroundMusic();
                break;

            // rewind background music
            case 4:
                SimpleAudioEngine.sharedEngine().rewindBackgroundMusic();
                break;

            // is background music playing
            case 5:
                if (SimpleAudioEngine.sharedEngine().isBackgroundMusicPlaying())
                {
                    Debug.WriteLine("background music is playing");
                }
                else
                {
                    Debug.WriteLine("background music is not playing");
                }
                break;

            // play effect
            case 6:
                m_nSoundId = SimpleAudioEngine.sharedEngine().playEffect(CCFileUtils.fullPathFromRelativePath(EFFECT_FILE));
                break;

            // play effect
            case 7:
                m_nSoundId = SimpleAudioEngine.sharedEngine().playEffect(CCFileUtils.fullPathFromRelativePath(EFFECT_FILE), true);
                break;

            // stop effect
            case 8:
                SimpleAudioEngine.sharedEngine().stopEffect(m_nSoundId);
                break;

            // unload effect
            case 9:
                SimpleAudioEngine.sharedEngine().unloadEffect(CCFileUtils.fullPathFromRelativePath(EFFECT_FILE));
                break;

            // add bakcground music volume
            case 10:
                SimpleAudioEngine.sharedEngine().setBackgroundMusicVolume(SimpleAudioEngine.sharedEngine().getBackgroundMusicVolume() + 0.1f);
                break;

            // sub backgroud music volume
            case 11:
                SimpleAudioEngine.sharedEngine().setBackgroundMusicVolume(SimpleAudioEngine.sharedEngine().getBackgroundMusicVolume() - 0.1f);
                break;

            // add effects volume
            case 12:
                SimpleAudioEngine.sharedEngine().setEffectsVolume(SimpleAudioEngine.sharedEngine().getEffectsVolume() + 0.1f);
                break;

            // sub effects volume
            case 13:
                SimpleAudioEngine.sharedEngine().setEffectsVolume(SimpleAudioEngine.sharedEngine().getEffectsVolume() - 0.1f);
                break;
            }
        }
Пример #3
0
        public override void onExit()
        {
            base.onExit();

            SimpleAudioEngine.sharedEngine().end();
        }