Spritebatch删除多维数据集的正面

时间:2013-09-04 12:46:22

标签: c# xna monogame

Picture showing the issue

我无法解释这个问题。

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

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();
    }
}

2 个答案:

答案 0 :(得分:1)

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

当您将呼叫更改为此时:

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

...它会覆盖默认设置并将设备设置为CullNone。您不一定需要使用SpriteSortMode.Immediate,但如果您的方框有错误的绕线顺序,则需要指定非默认的RasterizerState

至于为什么这种方法适用于某些平台而不适用于其他平台,我不能说。你遇到了all abstractions are leaky的事实。 MonoGame在大多数平台上都是在OpenGL之上实现的,因此幕后发生的事情根本不同。

通常,当您尝试跨平台时,最好是特定关于您正在做的事情 - 在这种情况下,通过在{{1中手动指定设备状态 - 因为它为实现提供了有关您实际尝试完成的更多信息。

答案 1 :(得分:0)

也许移动

GraphicsDevice.Clear(Color.Cyan);

在spriteBtach

之前
GraphicsDevice.Clear(Color.Cyan);
spriteBatch.Begin(SpriteSortMode.Immediate, null, null, d, rs); 
controls.Draw(spriteBatch);
spriteBatch.End();