Пример #1
0
 public void PlaySoundAtNode(SceneNode node, string soundID)
 {
     if (hasSound)
     {
         SoundEntity entity    = null;
         string      soundFile = findSoundFileByID(soundID);
         if (!string.IsNullOrEmpty(soundFile))
         {
             entity = soundEngine.CreateSoundEntity(findSoundFileByID(soundID), node, "", false, false);
             entity.Play();
             entities.Add(entity);
         }
     }
 }
Пример #2
0
        /// <summary>
        /// Function that handles tasks that trigger when a key is pressed.
        /// </summary>
        /// <param name="e">Data passed by the event handler that calls the function.</param>
        /// <returns></returns>
        public bool KeyPressed(MOIS.KeyEvent e)
        {
            switch (e.key)
            {
            case MOIS.KeyCode.KC_LEFT:
            case MOIS.KeyCode.KC_A:
                position--;
                if (position < -1)
                {
                    position = -1;
                }
                break;

            case MOIS.KeyCode.KC_RIGHT:
            case MOIS.KeyCode.KC_D:
                position++;
                if (position > 1)
                {
                    position = 1;
                }
                break;

            case MOIS.KeyCode.KC_SPACE:
                switch (position)
                {
                case -1:
                    running = false;
                    break;

                case 0:
                    if (soundEntity != null)
                    {
                        if (soundEntity.IsPlaying())
                        {
                            soundEntity.Stop();
                        }
                        else
                        {
                            soundEntity.Play();
                        }
                        break;
                    }

                    soundEntity = smgr.CreateSoundEntity("Assets/Sounds/DrumMono.ogg", mgr.GetSceneNode("Drum"), "Drum", false, false);
                    soundEntity.SetReferenceDistance(.5f);
                    soundEntity.SetMaxDistance(5);
                    soundEntity.Play();
                    break;

                case 1:
                    if (ambientSound != null)
                    {
                        if (ambientSound.IsPlaying())
                        {
                            ambientSound.Stop();
                        }
                        else
                        {
                            ambientSound.Play();
                        }
                        break;
                    }
                    ambientSound = smgr.CreateAmbientSound("Assets/Sounds/Tune.ogg", "Tune", false, false);
                    ambientSound.Play();
                    break;
                }
                break;

            case MOIS.KeyCode.KC_ESCAPE:
                running = false;
                break;
            }

            return(true);
        }