我的单一游戏根本不会出现

时间:2017-11-07 22:34:05

标签: c# drawing draw monogame

当我尝试运行我创建的这个monogame项目时,唯一显示的东西(在一个小窗口中出于某些原因,当我选择this.graphics.ApplyChanges();用于图形显示模式)向上是一个矢车菊蓝屏幕。

这是我的monogame项目中的绘图和加载功能:

        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            fenetre = graphics.GraphicsDevice.Viewport.Bounds;
            fenetre.Width = graphics.GraphicsDevice.DisplayMode.Width;
            fenetre.Height = graphics.GraphicsDevice.DisplayMode.Height;

            heros = new GameObject();
            heros.nbVie = 5;
            heros.vitesse = 5;

            //load ammos of the hero
            for (int i = 0; i < munitions.Length; i++)
            {
                munitions[i] = new GameObject();
                munitions[i].nbVie = 10;
                munitions[i].vitesse = 10;
                munitions[i].sprite = Content.Load<Texture2D>("snowball");
            }
            //loads ennemy
            for (int i = 0; i < ennemy.Length; i++)
            {
                ennemy[i] = new GameObject();
                ennemy[i].nbVie = 0;
                ennemy[i].vitesse = 10;
                ennemy[i].sprite = Content.Load<Texture2D>("bowser");
                ennemy[i].position = ennemy[i].sprite.Bounds;
            }

            spriteBatch = new SpriteBatch(GraphicsDevice);
            heros.sprite = Content.Load<Texture2D>("snowball");

            Point point = fenetre.Center;
            Rectangle pos = new Rectangle(fenetre.Center.X, fenetre.Center.Y, heros.sprite.Width, heros.sprite.Height);
            heros.position = pos;
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            spriteBatch.Begin();
            //dessine les munitions du heros
            for (int i = 0; i < munitions.Length; i++)
            {
                if(munitions[i].nbVie>0)
                {
                    spriteBatch.Draw(munitions[i].sprite, munitions[i].position, Color.White);
                }
            }

            //draws ennemy
            for (int i = 0; i < ennemy.Length; i++)
            {
                if(ennemy[i].nbVie>0)
                {
                    spriteBatch.Draw(ennemy[i].sprite, ennemy[i].position, Color.White);
                }
            }
            //draws hero
                spriteBatch.Draw(heros.sprite, heros.position, Color.White);
            spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}

0 个答案:

没有答案