XNA游戏屏幕变白

时间:2015-01-15 11:20:57

标签: c# xna

当我玩游戏时,它会正确绘制。但是我突然得到一个白色的屏幕。左上方仍然显示文字,但非常模糊。

知道是什么原因引起的吗?我绝对没有错误所以它必须是一个简单的东西。

哦,这很奇怪:这只发生在我的笔记本电脑上!我的一些朋友使用相同的代码和相同的项目,并且工作正常。

Game1的draw方法中的代码:

 protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(Color.Black);
            if (startMenu.showMenu)
            {
                SpriteBatch batch = new SpriteBatch(graphics.GraphicsDevice);
                batch.Begin();
                startMenu.Draw(batch);
                batch.End();
            }
            if (selectedLevel != null && !startMenu.showMenu)
            {
                spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null,
                selectedLevel.GetCamera().getViewMatrix(new Vector2(1.0f)));
                for (int layer_inc = 0; layer_inc <= selectedLevel.layers.Count() - 1; layer_inc++)
                {
                    selectedLevel.layers[layer_inc].Draw(gameTime, spriteBatch);
                }
                if (selectedLevel.GetPlayer().IsAlive())
                {
                    Weapon weapon = selectedLevel.GetPlayer().GetWeapon();
                    weapon.Draw(gameTime, spriteBatch);


                    if (weapon is ShootableWeapon)
                    {
                        ShootableWeapon shootableWeapon = (ShootableWeapon)weapon;

                        if (shootableWeapon.getAmmo().Count() > 0)
                        {
                            for (int ammo_inc = 0; ammo_inc <= shootableWeapon.getAmmo().Count() - 1; ammo_inc++)
                            {
                                shootableWeapon.getAmmo()[ammo_inc].Draw(gameTime, spriteBatch);
                            }
                        }
                    }
                    if (selectedLevel.GetPlayer().isMeditating())
                    {
                        Player player = selectedLevel.GetPlayer();
                        //CalculatorBoost calculatorBoost = ((CalculatorBoost)player.getBoost());
                        //calculatorBoost.Draw(spriteBatch);
                        MeditationBoost meditationBoost = ((MeditationBoost)player.getBoost());
                        meditationBoost.Draw(spriteBatch, player.position);
                    }
            }

            foreach (MovableObject movableObject in selectedLevel.movableObjects)
            {
                if (movableObject is Enemy)
                {
                    Enemy enemy = (Enemy)movableObject;
                    ThrowAttack attack = ((ThrowAttack)enemy.getAttack());
                    if (attack != null && attack.getThrowObject() != null)
                    {

                        attack.getThrowObject().Walk(Direction.Right, attack.getThrowObject().speed);
                        attack.getThrowObject().Update(gameTime);
                        attack.getThrowObject().Draw(spriteBatch);
                    }
                }
            }
            updateScreenText(spriteBatch);
            try
            {

                spriteBatch.End();
            }
            catch (ObjectDisposedException ex)
            {
                Debug.Write(ex.StackTrace);
            }

        }

        base.Draw(gameTime);
    }

screentext代码:

 public void updateScreenText(SpriteBatch spriteBatch)
        {
            Player player = selectedLevel.GetPlayer();
            String weaponName = player.GetWeapon().textureName;

            spriteBatch.DrawString(font, "Selected Weapon: " + weaponName.Substring(0, 1).ToUpper() + weaponName.Substring(1)
                , selectedLevel.GetCamera().Position + new Vector2(10, 10), Color.Green);

            spriteBatch.DrawString(font, "HP: " + player.GetHp(), selectedLevel.GetCamera().Position + new Vector2(10, 35)
                , Color.Green);

            if (!player.IsAlive())
                spriteBatch.DrawString(font, "Game Over!", selectedLevel.GetCamera().Position + new Vector2(260, 240), Color.Red);

            if (selectedLevel.GetMovableObjects().Count == 1)
                spriteBatch.DrawString(font, "You've won!", selectedLevel.GetCamera().Position + new Vector2(180, 240), Color.Red);
        }

白屏图片: White screen

0 个答案:

没有答案