【问题标题】:Spritebatch doesn't work精灵批处理不起作用
【发布时间】:2013-06-14 02:36:43
【问题描述】:

在使用 Monogame 开发我的游戏时,我想通过屏幕右上角的按钮暂停游戏......但是当其他元素正在绘制时,只有 pauseImage 不显示。 我把 Draw() 函数的代码放在这里:

SBatch.Begin();

            SBatch.Draw(PauseImage,new Vector2(1024,50), Color.White);

            if (_isPaused)
            {
                SBatch.Draw(ResumeImage, new Vector2(500, 300), Color.White);
                SBatch.Draw(QuitImage,new Vector2(600,300),Color.White);
            }
            SBatch.Draw(_castel.Image, _castel.PosCastle, Color.White);


            SBatch.DrawString(LineFont, _life + "/1000", _castel.PosLife, Color.Black);
            SBatch.DrawString(LineFont, "Score:" + _score, new Vector2(_castel.PosLife.X,_castel.PosLife.Y+50), Color.Black);


            SBatch.End();


            foreach (EnemyUnit t in _enemyUnits)
            {
                t.AnimatedSprite.Draw(SBatch, t.Pos);
                if (_mouseState.LeftButton == ButtonState.Pressed && t.Area.Limit(_mouseState))
                {
                    float temp;
                    temp = t.Pos.Y;
                    t.Pos.Y -= 470;
                    MouseAttack.Draw(SBatch, t.Pos);
                    t.Pos.Y = temp;
                }
            }


            SBatch.End();
        }

        base.Draw(gameTime);

图像是一个普通的 png 加载到 Texture2D 对象中。

【问题讨论】:

  • 为什么要调用 SBatch.End() 两次?

标签: drawing monogame


【解决方案1】:

将您绘制 pauseImage 的部分移到代码的末尾,这样它就在最后绘制,并且位于其他所有内容之上。然后从您的代码中删除第一个 SBatch.End()

foreach (EnemyUnit t in _enemyUnits)
{
    t.AnimatedSprite.Draw(SBatch, t.Pos);
    if (_mouseState.LeftButton == ButtonState.Pressed && t.Area.Limit(_mouseState))
    {
        float temp;
        temp = t.Pos.Y;
        t.Pos.Y -= 470;
        MouseAttack.Draw(SBatch, t.Pos);
        t.Pos.Y = temp;
    }
}

if (_isPaused)
{
    SBatch.Draw(ResumeImage, new Vector2(500, 300), Color.White);
    SBatch.Draw(QuitImage,new Vector2(600,300),Color.White);
}

SBatch.End();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-13
    • 2017-12-09
    • 2012-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多