CreateInstance() public method

Creates a new SoundEffectInstance for this SoundEffect.
Creating a SoundEffectInstance before calling SoundEffectInstance.Play() allows you to access advanced playback features, such as volume, pitch, and 3D positioning.
public CreateInstance ( ) : SoundEffectInstance
return SoundEffectInstance
Beispiel #1
0
        private SoundEffectInstance GetInstance(SoundEffect effect)
        {
            #if WINDOWS_PHONE
            // Names of resources for some reason don't work on XNA 4.0 targetting Phone 7.1
            // For now (first release), just don't cache sounds.
            return effect.CreateInstance();
            #else
            if (!_cachedEffects.ContainsKey(effect.Name))
            {
                _cachedEffects.Add(effect.Name, effect.CreateInstance());
            }

            return _cachedEffects[effect.Name];
            #endif
        }
Beispiel #2
0
 public Audio(string bestand, bool loop)
 {
     soundEffect = Program.INSTANCE.Content.Load<SoundEffect>(bestand);
     instance = soundEffect.CreateInstance();
     instance.IsLooped = loop;
     playingSound = true;
 }
Beispiel #3
0
        public GameStateManagementGame()
        {
            Content.RootDirectory = "Content";

            graphics = new GraphicsDeviceManager(this);
            //TargetElapsedTime = TimeSpan.FromTicks(333333);
            TargetElapsedTime = TimeSpan.FromTicks(333);

            #if WINDOWS_PHONE
            graphics.IsFullScreen = true;
            InitializeLandscapeGraphics();
            #endif

            screenFactory = new ScreenFactory();
            Services.AddService(typeof(IScreenFactory), screenFactory);
            screenManager = new ScreenManager(this);
            Components.Add(screenManager);

            #if WINDOWS_PHONE
            // hook
            Microsoft.Phone.Shell.PhoneApplicationService.Current.Launching +=
                new EventHandler<Microsoft.Phone.Shell.LaunchingEventArgs>(GameLaunching);
            Microsoft.Phone.Shell.PhoneApplicationService.Current.Activated +=
                new EventHandler<Microsoft.Phone.Shell.ActivatedEventArgs>(GameActivated);
            Microsoft.Phone.Shell.PhoneApplicationService.Current.Deactivated +=
                new EventHandler<Microsoft.Phone.Shell.DeactivatedEventArgs>(GameDeactivated);
            #else
            AddInitialScreens();
            #endif
            gameMusic = Content.Load<SoundEffect>("sounds/GamePlayHalfBit");
            gameMusicI = gameMusic.CreateInstance();
            gameMusicI.IsLooped = true;
            gameMusicI.Play();
        }
Beispiel #4
0
        public static void PlaySound(SoundEffect Sound)
        {
            SoundEffectInstance soundEngineInstance;

            soundEngineInstance = Sound.CreateInstance();
            soundEngineInstance.Play();
        }
Beispiel #5
0
 /// <summary>
 /// Erstellt eine neue SoundEffect-Datei mit dem angegebenen Anzeigenamen und des angegebenen SoundEffect-Objekts.
 /// </summary>
 public SoundEffectFile(string name, SoundEffect soundEffect, Sound soundType)
 {
     Name = name;
     SoundEffect = soundEffect;
     Instance = soundEffect.CreateInstance ();
     SoundType = soundType;
 }
Beispiel #6
0
 public CSound(SoundEffect fx, bool Track)
 {
     _sfxInstance = fx.CreateInstance();
     _sfx = null;
     _song = null;
     _track = Track;
 }
Beispiel #7
0
 public static void playSound(SoundEffect soundEffect)
 {
     SoundEffectInstance instance = soundEffect.CreateInstance();
     instance.Volume = Game.volume;
     instance.Play();
     soundEffects.Add(instance);
 }
Beispiel #8
0
 public LoopingSoundEffect(SoundEffect soundEffect, float volume)
 {
     sound = soundEffect.CreateInstance();
     sound.IsLooped = true;
     this.volume = sound.Volume = volume;
     LoopingSoundEffects.Add(this);
 }
Beispiel #9
0
        public PlayingState(Game game)
            : base(game)
        {
            game.Services.AddService(typeof(IPlayingState), this);

            PlayerShip = new Player(OurGame);
            GameThrusterManager = new ThrusterManager(OurGame);

            PlayerShip.GameThrusterManager = GameThrusterManager;

            GameFoodManager = new FoodManager(OurGame);
            PlayerShip.GameFoodManager = GameFoodManager;
            GameFoodManager.PlayerShip = PlayerShip;

            GamePowerupManager = new PowerUpManager(OurGame);
            PlayerShip.GamePowerupManager = GamePowerupManager;
            GamePowerupManager.PlayerShip = PlayerShip;

            OurGame.Components.Add(PlayerShip);
            OurGame.Components.Add(GameThrusterManager);
            OurGame.Components.Add(GameFoodManager);
            OurGame.Components.Add(GamePowerupManager);

            PlayerShip.Enabled = false;
            GameFoodManager.Enabled = false;
            GameThrusterManager.Enabled = false;
            GamePowerupManager.Enabled = false;
            PlayerShip.Visible = false;
            GameFoodManager.Visible = false;
            GameThrusterManager.Visible = false;
            GamePowerupManager.Visible = false;

            soundEffect = Content.Load<SoundEffect>("Music");
            soundEffectIntance = soundEffect.CreateInstance();
        }
        public void CreateSoundInstance(string SoundID)
        {
            switch (SoundID)
            {

                case "finalMap1":
                    SoundFromFile = (SoundEffect)ContentRepository.Content["1-"];
                    InstanceOfSound = SoundFromFile.CreateInstance();
                    break;

                case "finalMap2":
                    SoundFromFile = (SoundEffect)ContentRepository.Content["2-"];
                    InstanceOfSound = SoundFromFile.CreateInstance();
                    break;
                case "finalMap3":
                    SoundFromFile = (SoundEffect)ContentRepository.Content["3-"];
                    InstanceOfSound = SoundFromFile.CreateInstance();
                    break;
                case "4":
                    SoundFromFile = (SoundEffect)ContentRepository.Content["4-"];
                    InstanceOfSound = SoundFromFile.CreateInstance();
                    break;
                case "5":
                    SoundFromFile = (SoundEffect)ContentRepository.Content["5-"];
                    InstanceOfSound = SoundFromFile.CreateInstance();
                    break;
                case "6":
                    SoundFromFile = (SoundEffect)ContentRepository.Content["6-"];
                    InstanceOfSound = SoundFromFile.CreateInstance();
                    break;
                default:
                    //throw new Exception("No Sound for this ID");
                    break;
            }
        }
Beispiel #11
0
        public void Init()
        {
            speed = 5;//1000 / speed;
            player = new Player(game, this, new Rectangle(512, 0, 32, 32));
            game.Components.Add(player);
            Block floor = new Block(game, this, new Rectangle(0, 736, 1024, 32), Color.SpringGreen, 0, 0);//740
            blocks.Add(floor);

            game.Components.Add(floor);

            CheckNextBlockSpawn();

            this.highScore = new HighScoresWindow(game);
            game.Components.Add(this.highScore);

            this.scoreText = new Text(game, "Score: " + this.points, new Vector2(0,0), Color.Blue);
            game.Components.Add(this.scoreText);

            music = this.game.Content.Load<SoundEffect>("home_at_last");

            musicInstance = music.CreateInstance();
            musicInstance.IsLooped = true;
            musicInstance.Play();

            points = 0;
        }
Beispiel #12
0
        /// <summary>
        /// The parameterized constructor for the player class
        /// </summary>
        /// <param name="pTexture">The texture that the player will use</param>
        /// <param name="g">The GraphicsDeviceManager that will be used</param>
        public Player(Texture2D pTexture, GraphicsDeviceManager gdm, World w, Texture2D fTexture)
        {
            //Load the texture and set the vectors
            graphic = gdm;
            screenWidth = gdm.PreferredBackBufferWidth;
            screenHeight = gdm.PreferredBackBufferHeight;
            position = new Vector2(150, 50);
            body = new Rectangle((int)position.X, (int)position.Y, 50, 50);
            //TODO: add content manager

            burning = w.game.Content.Load<SoundEffect>("Audio/WAVs/fire");
            burning2 = burning.CreateInstance();

            texture = pTexture;
            flameTexture = fTexture;
            velocity = new Vector2(0, 0);
            world = w;
            world.Player = this;
            //Set the player state
            hState = HorizontalState.standing;

            //Make an array of three torches
            torches = new Torch[999];
            for (int i = 0; i < torches.Length; i++)
            {
                torches[i] = new Torch(this, fTexture, w);
            }
        }
Beispiel #13
0
 public Effect(double lengthInMilliseconds, SoundEffect sound)
 {
     LengthInMilliseconds = lengthInMilliseconds;
     if (sound != null) {
         sound.CreateInstance ().Play ();
     }
 }
Beispiel #14
0
        public static void Initialize(ContentManager content)
        {
            scream = content.Load<SoundEffect>("Assets/Sounds/deathScream");
            collectSound = content.Load<SoundEffect>("Assets/Sounds/itemCollect");
            checkpointHell = content.Load<SoundEffect>("Assets/Sounds/CheckpointHell");
            checkpointCrystal = content.Load<SoundEffect>("Assets/Sounds/CheckpointCristall");
            fireball = content.Load<SoundEffect>("Assets/Sounds/Fireball");
            freezingIce = content.Load<SoundEffect>("Assets/Sounds/freezingIce");
            whip = content.Load<SoundEffect>("Assets/Sounds/whip");
            laser = content.Load<SoundEffect>("Assets/Sounds/laser");
            SeraphinScream = content.Load<SoundEffect>("Assets/Sounds/SeraphinScream");
            thunder = content.Load<SoundEffect>("Assets/Sounds/thunder");
            spear = content.Load<SoundEffect>("Assets/Sounds/spear");
            claws = content.Load<SoundEffect>("Assets/Sounds/claws");
            mainMenu = content.Load<SoundEffect>("Assets/Sounds/mainMenu");
            menu = mainMenu.CreateInstance();
            menu.IsLooped = true;
            punch = content.Load<SoundEffect>("Assets/Sounds/punch");
            waterSound = content.Load<SoundEffect>("Assets/Sounds/water");
            water = waterSound.CreateInstance();
            spawn = content.Load<SoundEffect>("Assets/Sounds/spawn");
            minionsFraktus = content.Load<SoundEffect>("Assets/Sounds/minions");
            goldCave = content.Load<SoundEffect>("Assets/Sounds/GoldCave");
            cave = goldCave.CreateInstance();
            //cave.IsLooped = true;

            //background crystal
            crystalBackground = content.Load<SoundEffect>("Assets/Sounds/crystalBackground");
            crystalBG = crystalBackground.CreateInstance();
            crystalBG.Volume = 0.25f;
            crystalBG.IsLooped = true;
        }
 public SmallMarioJumpEffect()
 {
     backgroundSoundEffect = SoundEffect.FromStream(backgroundSoundFile);
     instance = backgroundSoundEffect.CreateInstance();
     instance.Volume = 0.25f;
     instance.IsLooped = false;
 }
Beispiel #16
0
        public static void Initialize(ContentManager content)
        {
            try
            {

                Start_Bgm = content.Load<SoundEffect>(@"Sounds\\Start");
                Start_Bgm_Instance = Start_Bgm.CreateInstance();
                Start_Bgm_Instance.IsLooped = true;

                Stage1_3_Bgm = content.Load<SoundEffect>(@"Sounds\\Stage1_3");
                Stage1_3_Bgm_Instance = Stage1_3_Bgm.CreateInstance();
                Stage1_3_Bgm_Instance.IsLooped = true;

                Stage4_6_Bgm = content.Load<SoundEffect>(@"Sounds\\Stage4_6");
                Stage4_6_Bgm_Instance = Stage4_6_Bgm.CreateInstance();
                Stage4_6_Bgm_Instance.IsLooped = true;

                playerShot = content.Load<SoundEffect>(@"Sounds\\Shot1");
                enemyShot = content.Load<SoundEffect>(@"Sounds\\Shot2");

                enemy3Shot = content.Load<SoundEffect>(@"Sounds\\Explosion1");
                Enemy6_pattern1 = content.Load<SoundEffect>(@"Sounds\\Enemy6_pattern1");
                Enemy6_pattern1_2 = content.Load<SoundEffect>(@"Sounds\\Enemy6_pattern1_2");
                for (int x = 1; x <= explosionCount; x++)
                {
                    explosions.Add(content.Load<SoundEffect>(@"sounds\Explosion" + x.ToString()));
                }
            }
            catch
            {
                Debug.Write("SoundManager Initialization Failed");
            }
        }
Beispiel #17
0
        public GameManager(Game game, int level)
        {
            mGame = game;

            mPlayer1 = new Character(game, new Pointf(400, 200), new Size(32, 32), new Velocity(), PlayerIndex.One);
            mPlayer2 = new Character(game, new Pointf(350, 200), new Size(32, 32), new Velocity(), PlayerIndex.Two);
            mBoss = null;
            mLevel = level;
            switch (level)
            {
                case 1:
                    mMap = MapBuilder.BuildLevel1(mGame, new Size(game.Window.ClientBounds.Width, game.Window.ClientBounds.Height - Hud.HUD_HEIGHT), ref mPlayer1);
                    mPlayer1.mPosition = new Pointf(MapHelper.GetPointForColumnAndLevel(0.5f, 1));
                    mPlayer2.mPosition = new Pointf(MapHelper.GetPointForColumnAndLevel(0.5f, 1));
                    mBackgroundSong = mGame.Content.Load<Song>("music/Electrolyte - New Mission");
                    break;
                case 2:
                    mMap = MapBuilder.BuildSolo(mGame, new Size(game.Window.ClientBounds.Width, game.Window.ClientBounds.Height - Hud.HUD_HEIGHT), ref mPlayer1);
                    mPlayer1.mPosition = new Pointf(MapHelper.GetPointForColumnAndLevel(0.5f, 1));
                    mPlayer2.mPosition = new Pointf(MapHelper.GetPointForColumnAndLevel(MapHelper.GetLastColumn()-1.5f, 1));
                    mBackgroundSong = mGame.Content.Load<Song>("music/Electrolyte - Plus vs Minus");
                    break;
                case 3:
                    mMap = MapBuilder.BuildBossLevel(mGame, new Size(game.Window.ClientBounds.Width, game.Window.ClientBounds.Height - Hud.HUD_HEIGHT), ref mPlayer1);
                    mBoss = new Character(game, new Pointf(350, MapHelper.GetPlatformYAtLevel(1.5f)), new Size(64, 64), new Velocity(), PlayerIndex.Three);
                    mBackgroundSong = mGame.Content.Load<Song>("music/Electrolyte - Volt");
                    break;
            }

            mHud = new Hud(new Pointf(0, game.Window.ClientBounds.Height - Hud.HUD_HEIGHT), mGame, level);

            mIsPlayingSound = false;
            mGangnamSound = game.Content.Load<SoundEffect>("newgangnam");
            mGangnamInstance = mGangnamSound.CreateInstance();
        }
Beispiel #18
0
        public Sounds(Song song1, Song song2, Song song3, SoundEffect blimpEngineSound, SoundEffect explosionSound, SoundEffect failedSound,
            Song gameStartSound, SoundEffect playerEngineSound, SoundEffect rewardSound, SoundEffect shotSound)
        {
            level1Music = song1;
            level2Music = song2;
            level3Music = song3;
            MediaPlayer.IsRepeating = true;

            blimpEngineSE = blimpEngineSound;
            blimpEngineSEI = blimpEngineSE.CreateInstance();
            blimpEngineSEI.IsLooped = true;
            blimpEngineSEI.Pitch = 0.0f;
            blimpEngineSEI.Pan = 0.0f;

            missileEngineSE = blimpEngineSound;
            missileEngineSEI = missileEngineSE.CreateInstance();
            missileEngineSEI.IsLooped = true;
            missileEngineSEI.Pitch = 1.0f;
            missileEngineSEI.Pan = 0.0f;

            playerEngineSE = playerEngineSound;
            playerEngineSEI = playerEngineSE.CreateInstance();
            playerEngineSEI.IsLooped = true;
            playerEngineSEI.Pitch = -1.0f;

            explosionSE = explosionSound;
            failedSE = failedSound;
            gameStart = gameStartSound;
            rewardSE = rewardSound;
            shotSE = shotSound;
        }
        public void LoadContent(SpriteBatch spriteBatch, ContentManager Content, Viewport viewport, 
            Camera camera, Texture2D enemyTexture, GraphicsDeviceManager graphics, 
            SoundEffect _backgroundMusic, GameController _gameController, 
            SoundEffect _fireballSound, SpriteFont _spritefont, Texture2D _bossTexture)
        {
            _enemyTexture = enemyTexture;
            this.camera = camera;
            _graphics = graphics;

            spritefont = _spritefont;

            bossTexture = _bossTexture;

            backgroundMusic = _backgroundMusic;
            fireballSound = _fireballSound;

            _content = Content;
            gameController = _gameController;
            character = Content.Load<Texture2D>("imp");
            Flame.SetTexture(Content.Load<Texture2D>("Flames"));
            
            soundEffectInstance = backgroundMusic.CreateInstance();

            onFirstLevel = false;
            onSecondLevel = false;
            onThirdLevel = false;
            onFourthLevel = false;

        }
Beispiel #20
0
        //plays a sound once and doesn’t store the reference into memory
        public static void playSound(string filename, ContentManager Content)
        {
            int index = 1;
                SoundEffectInstance soundEngineInstance;
                if (lookUpTable.ContainsKey(filename))
                {

                    lookUpTable.TryGetValue(filename, out index);
                    soundEngineInstance = mySounds.ElementAt(index);
                    if (soundEngineInstance.State == SoundState.Paused)
                    {
                        soundEngineInstance.Resume();
                    }
                    else if (soundEngineInstance.State == SoundState.Stopped)
                    {
                        soundEngineInstance.Play();
                    }
                }
                else
                {
                    soundEngine = Content.Load<SoundEffect>(filename);
                    soundEngineInstance = soundEngine.CreateInstance();
                    mySounds.Add(soundEngineInstance);

                    lookUpTable.Add(filename, numSounds);
                    numSounds++;
                    soundEngineInstance.IsLooped = false;
                    soundEngineInstance.Volume = 0.5f;
                    soundEngineInstance.Play();
                }
        }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="spriteBatch"></param>
    /// <param name="contentManager"></param>
    override public void Draw(SpriteBatch spriteBatch, ContentManager contentManager)
    {
      if (_isAlive)
      {
        Texture2D texture = _textureFlyweight.LoadTexture2D(this.ResourcePath,contentManager,_hasTransparency);
        Rectangle rect = _getScaledRectangle();
        spriteBatch.Draw(texture, rect, Color.White);

        //begin sound play on first Draw() call.
        if (_once)
        {
          _once = false;

          try
          {
            _sound = contentManager.Load<SoundEffect>(_soundFxPath);
            SoundEffectInstance instance = _sound.CreateInstance();
            //float volume = 1.0f;
            //float pitch = 0.0f;
            //float pan = 0.0f;
            instance.Play();// or use: _sound.Play(volume, pitch, pan); and alter pan!
          }
          catch (Exception e)
          {
            System.Console.WriteLine("SOUND FAILED TO LOAD. e:"+e.Message+e.StackTrace);
          }
        }
      }
    }
Beispiel #22
0
 //Modular Constructor
 public SoundObject(SoundEffect target, Vector2 posn)
 {
     this.sound = target;
     this.position = posn;
     this.isModular = true;
     this.dynamic = sound.CreateInstance();
 }
Beispiel #23
0
        public AudioEffect(SoundEffect soundEffect)
        {
            _soundEffect = soundEffect;
            Duration = _soundEffect.Duration.TotalSeconds;

            _soundEffectInstance = soundEffect.CreateInstance();
        }
 /// <summary>
 /// Constructor of looped sound player
 /// </summary>
 /// <param name="game"> instance of game to be used for content load </param>
 /// <param name="name"> path to the wav file to be played </param>
 public SoundPlayerLoop(Microsoft.Xna.Framework.Game game, string name)
     : base(game)
 {
     sound = game.Content.Load<SoundEffect>(name);
     soundInstance = sound.CreateInstance();
     soundInstance.IsLooped = true;
 }
Beispiel #25
0
        public Bullet(World world, Car _car, Texture2D _dummyTexture)
        {
            car = _car;
            dummyTexture = _dummyTexture;

            bulletPhysicsObject=  BodyFactory.CreateRectangle(world, 0.1f, 0.1f, 1f, Vector2.Zero);
            bulletPhysicsObject.BodyType = BodyType.Dynamic;

            bulletPhysicsObject.IsSensor = true;
            bulletPhysicsObject.IsBullet = true;

            isGoing = false;

            bulletPhysicsObject.IgnoreCollisionWith(car._compound);

            bulletPhysicsObject.CollisionCategories = Category.Cat20;

            bulletPhysicsObject.OnCollision += bullet_OnCollision;
            graphics = GameServices.GetService<GraphicsDeviceManager>();

            pencilTexture = GameServices.GetService<ContentManager>().Load<Texture2D>("Images/pencilTextire");

            laserVertices = new VertexPositionColorTexture[6];

            laserVertices[0].Color = car.mColor;
            laserVertices[1].Color = car.mColor;
            laserVertices[2].Color = car.mColor;
            laserVertices[3].Color = car.mColor;
            laserVertices[4].Color = car.mColor;
            laserVertices[5].Color = car.mColor;

            laserSound = GameServices.GetService<ContentManager>().Load<SoundEffect>("Sounds/laserorribiledimmerda");

            laserSoundInstance=laserSound.CreateInstance();
        }
Beispiel #26
0
 public override void Initialize()
 {
     base.Initialize();
     _loop = Game.Content.Load<SoundEffect>("AudioContent/loop");
     _loopInstance = _loop.CreateInstance();
     _loopInstance.IsLooped = true;
     _loopInstance.Volume = 0.3f;
 }
Beispiel #27
0
		/// <summary>
		/// LoadContent will be called once per game and is the place to load
		/// all of your content.
		/// </summary>
		protected override void LoadContent ()
		{
			spriteBatch = new SpriteBatch (GraphicsDevice);

			sExplosion = Content.Load<SoundEffect> ("ExplosionSound");
			tExplosion = Content.Load<Texture2D> ("Explosion");
			eExplosion = sExplosion.CreateInstance ();
		}
        public static void AddEffect(string effectName, SoundEffect effect, bool playFromInstance)
        {
            if (playFromInstance)
            {
                if (_effectInstances == null) { _effectInstances = new Dictionary<string, SoundEffectInstance>(); }

                if (!_effectInstances.ContainsKey(effectName)) { _effectInstances.Add(effectName, effect.CreateInstance()); }
                else { _effectInstances[effectName] = effect.CreateInstance(); }
            }
            else
            {
                if (_effects == null) { _effects = new Dictionary<string, SoundEffect>(); }

                if (!_effects.ContainsKey(effectName)) { _effects.Add(effectName, effect); }
                else { _effects[effectName] = effect; }
            }
        }
Beispiel #29
0
		private SoundEffectInstance m_loopingInstance; //there SHOULD only be one of these...

		public SoundInfo(SoundEffect toWrap)
		{
			if (toWrap == null) return;

			m_effect = toWrap;
			m_instances = new List<SoundEffectInstance> { toWrap.CreateInstance() };
			m_loopingInstance = null;
		}
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            effect = Content.Load<SoundEffect>("woodburnlong");
            effectInstance = effect.CreateInstance();
        }
Beispiel #31
0
        /// <summary>
        /// Luo Sound-tyyppisen olion. Oliolla on ominaisuuksia kuten voimakkuus ja korkeus
        /// joita voidaan muuttaa soiton aikana.
        /// </summary>
        /// <returns></returns>
        public Sound CreateSound()
        {
            if (!Game.AudioEnabled)
            {
                return(null);
            }

            try
            {
                DoLoad();
                return(new Sound(xnaEffect.CreateInstance()));
            }
            catch (NoAudioHardwareException)
            {
                Game.Instance.OnNoAudioHardwareException();
                return(null);
            }
        }
Beispiel #32
0
 public GameMusic(SoundEffect soundEffect)
 {
     _instance          = soundEffect.CreateInstance();
     _instance.IsLooped = true;
 }