none
poner sonido cuando pulso tecla

    Pregunta

  • Bueno, vengo con otra pregunta que es basicamente como la enterior, quiero que cuando pulse una tecla me salga una cancion nueva de la que esta puesta, pero no pasa. Lo tengo puesto asi el codigo 

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Audio;
    using Microsoft.Xna.Framework.Content;
    using Microsoft.Xna.Framework.GamerServices;
    using Microsoft.Xna.Framework.Graphics;
    using Microsoft.Xna.Framework.Input;
    using Microsoft.Xna.Framework.Media;
    
    namespace Space_Platform
    {
        /// <summary>
        /// This is the main type for your game
        /// </summary>
        public class Game1 : Microsoft.Xna.Framework.Game
        {
            GraphicsDeviceManager graphics;
            SpriteBatch spriteBatch;
    
            public Game1()
            {
                graphics = new GraphicsDeviceManager(this);
                Content.RootDirectory = "Content";
    
            }
    
            //** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **//
    
            protected override void Initialize()
            {
              
                std = 1;
                std_d = 1;
                pos0 = new Vector2(0, 0);
                pos1 = new Vector2(244, 262);
                pos2 = new Vector2(573, 255);
                pos4 = new Vector2(392, 99);
                pos3 = new Vector2(5, 25);
                pos5 = new Vector2(400, 412);
               
                base.Initialize();
            }
    
            //** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **//
            Texture2D uno, pj1_izq, pj1_up, pj1_down, pj1_right, pj2_up, pj2_izq, pj2_down, pj2_der, inic, con, fon, platform;
            Song cfh, ma;
            Vector2 pos0, pos1, pos2, pos3, pos4, pos5;
            int o1, o2, o3, o4, std, std_d; //izq,der,aba,up //std 1=menu 2=juego, std_d 1menu
            //std_d 2=controles
    
            protected override void LoadContent()
            {
                // Create a new SpriteBatch, which can be used to draw textures.
                spriteBatch = new SpriteBatch(GraphicsDevice);
                uno = Content.Load<Texture2D>("imagenes/1");
                con = Content.Load<Texture2D>("imagenes/cont");
                inic = Content.Load<Texture2D>("imagenes/inc");
                pj1_izq = Content.Load<Texture2D>("imagenes/black");
                pj1_down = Content.Load<Texture2D>("imagenes/black");
                pj1_right = Content.Load<Texture2D>("imagenes/black");
                pj1_up = Content.Load<Texture2D>("imagenes/black");
                pj2_up = Content.Load<Texture2D>("imagenes/black");
                pj2_der = Content.Load<Texture2D>("imagenes/black");
                pj2_down = Content.Load<Texture2D>("imagenes/black");
                pj2_izq = Content.Load<Texture2D>("imagenes/black");
                fon = Content.Load<Texture2D>("imagenes/black");
                platform = Content.Load<Texture2D>("imagenes/black");
                cfh = Content.Load<Song>("Musica/cfh");
                ma = Content.Load<Song>("Musica/my apocalypse");
                
                  MediaPlayer.Play(cfh);
                    MediaPlayer.IsRepeating = true;
    
                  
                
    
            }
    
            /// <summary>
            /// UnloadContent will be called once per game and is the place to unload
            /// all content.
            /// </summary>
            protected override void UnloadContent()
            {
                // TODO: Unload any non ContentManager content here
            }
    
            /// <summary>
            /// Allows the game to run logic such as updating the world,
            /// checking for collisions, gathering input, and playing audio.
            /// </summary>
            /// <param name="gameTime">Provides a snapshot of timing values.</param>
            protected override void Update(GameTime gameTime)
            {
    
                if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                    this.Exit();
                
    
    
                if (std == 1)
                {
                    
                    if (Keyboard.GetState().IsKeyDown(Keys.D2))
                        std_d = 2;
                    if (Keyboard.GetState().IsKeyDown(Keys.B))
                        std_d = 1;
                    if (Keyboard.GetState().IsKeyDown(Keys.D1))
                        std = 2;
                }
                if (std == 2)
                {
                    MediaPlayer.Pause();
                    MediaPlayer.Play(ma);
                    MediaPlayer.IsRepeating = true;
                   
                }
                // TODO: Add your update logic here
    
                base.Update(gameTime);
            }

    hasta hay lo interesante. De hecho cuando pulso la tecla "2", veno que el rendimiento del PC aumenta, y encima no suena ninguna cancion


    • Editado Kainz97 sábado, 21 de abril de 2012 22:04
    sábado, 21 de abril de 2012 22:02

Respuestas

Todas las respuestas