0

显示问题的图片

我无能为力来解释这个问题。

这是我的主要绘制方法。如果我改变

controls.Draw(spriteBatch);
spriteBatch.End();
spriteBatch.Begin(); 

controls.Draw(spriteBatch);
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.Immediate, null, null, d, rs); 

块完美地绘制,除了在屏幕上没有绘制控件或文本。

d = new DepthStencilState(); //Class level
d.DepthBufferEnable = true;
d.DepthBufferWriteEnable = true;            
GraphicsDevice.DepthStencilState = d;
rs = RasterizerState.CullNone;
GraphicsDevice.RasterizerState = rs;

protected override void Draw(GameTime gameTime)
{
    GraphicsDevice.Clear(Color.Cyan);

    // need to do this on reach devices to allow non 2^n textures
    GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp; 
    //spriteBatch.Begin(SpriteSortMode.Immediate, null, null, d, rs);

    if (gameState == State.BREAKOUT)
    {
        wallBlock.Draw(camera);

        if (firstBlocks.Count < 49)
        {
            foreach (Block block in secondBlocks)
            {
               block.Draw(camera);
            }
        }

        foreach (Block block in firstBlocks)
        {
            block.Draw(camera);
        }

        ball.Draw(GraphicsDevice, camera.View, camera.Projection, spriteBatch);

        spriteBatch.Begin(SpriteSortMode.Immediate, null, null, d, rs); 
        controls.Draw(spriteBatch);
        spriteBatch.End();
        spriteBatch.Begin();
        if (ball.scoreMultiplier <= 1)
        {
            spriteBatch.DrawString(
                       scoreFont, 
                       "Score: " + 
                       scoreDiff + 
                       "\n Lives:" + 
                       ball.lives, 
                       new Vector2(100, 10), 
                       Color.Black);
        }
        else
        {
            spriteBatch.DrawString(
                       scoreFont, 
                       "Score: " + 
                       scoreDiff + 
                       "x" + 
                       ball.scoreMultiplier + 
                       " multiplier!" + 
                       "\n Lives:" 
                       + ball.lives, 
                       new Vector2(100, 10), 
                       Color.Black);
        }
        spriteBatch.End();
    }
}
4

2 回答 2

1

看起来你的盒子表面的缠绕顺序是向后的。调用默认SpriteBatch.Begin()方法会将设备的剔除模式重置为CullCounterClockwiseFace.

当您将呼叫更改为此:

spriteBatch.Begin(SpriteSortMode.Immediate, null, null, d, rs); 

...它覆盖了该默认值并将设备设置为CullNone. 你不一定需要使用SpriteSortMode.Immediate,但如果你的盒子有错误的缠绕顺序,你需要指定一个非默认的RasterizerState

至于为什么这在某些平台上有效,而在其他平台上无效,我不能说。您遇到了所有抽象都是泄漏的事实。MonoGame 在大多数平台上都是在 OpenGL 之上实现的,所以幕后发生的事情根本不同。

一般来说,当您尝试跨平台时,最好具体说明您正在做什么——在这种情况下,通过手动指定设备状态——SpriteBatch.Begin()因为它为实现提供了更多关于你在做什么的信息实际上试图完成。

于 2013-09-04T15:04:26.357 回答
0

也许搬家

GraphicsDevice.Clear(Color.Cyan);

它在 spriteBtach 之前

GraphicsDevice.Clear(Color.Cyan);
spriteBatch.Begin(SpriteSortMode.Immediate, null, null, d, rs); 
controls.Draw(spriteBatch);
spriteBatch.End();
于 2013-09-04T12:54:23.797 回答