Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Xna取款单工作不正常_C#_Xna - Fatal编程技术网

C# Xna取款单工作不正常

C# Xna取款单工作不正常,c#,xna,C#,Xna,我有一个2d纹理数组2d,它保存了这个数组中地图的不同部分。但我有一个问题,当我运行游戏时,地图绘制正确,但由于某种原因,数组[0,0]纹理与我的所有纹理重叠,包括我的玩家纹理和鼠标纹理。每一个其他纹理都与我的鼠标和播放器纹理正确重叠贴图 我现在真的很困惑,因为贴图纹理是使用嵌套for循环绘制在一起的 这是我的地图绘制方法,我在游戏的绘制方法中调用了该方法: public void Draw() { // Draws the Map from a 2D Array for (in

我有一个2d纹理数组2d,它保存了这个数组中地图的不同部分。但我有一个问题,当我运行游戏时,地图绘制正确,但由于某种原因,数组[0,0]纹理与我的所有纹理重叠,包括我的玩家纹理和鼠标纹理。每一个其他纹理都与我的鼠标和播放器纹理正确重叠贴图

我现在真的很困惑,因为贴图纹理是使用嵌套for循环绘制在一起的

这是我的地图绘制方法,我在游戏的绘制方法中调用了该方法:

public void Draw()
{
    // Draws the Map from a 2D Array
    for (int row = 0; row < mapTexture.GetLength(0); row++)
    {
        for (int col = 0; col < mapTexture.GetLength(1); col++)
        {
            spriteBatch.Draw(mapTexture[row, col], mapPosition[row, col], Color.White);
        }//end for
    }//end for
}//end Draw()
protected override void Draw(GameTime gameTime)
{
    GraphicsDevice.Clear(Color.CornflowerBlue);

    spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
    spriteBatch.Draw(mouseIcon, mouseIconPosition, Color.White);
    player.Draw();
    map.Draw();
    spriteBatch.End();

    base.Draw(gameTime);
}//end Draw()

尝试反转绘制顺序,并使用
SpriteSortMode.Deferred

您可以尝试使用重载SpriteBatch.Draw方法和depth。例如:

SpriteBatch.Draw(Texture2D,Vector2,Nullable,Color,Single,Vector2,Single,SpriteEffects,Single)向要渲染的一批精灵添加精灵,指定纹理、屏幕位置、可选源矩形、颜色着色、旋转、原点、比例、效果和排序深度

或者可以尝试更改图形的顺序:

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

    spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);

    map.Draw();  // first
    player.Draw();  // second
    spriteBatch.Draw(mouseIcon, mouseIconPosition, Color.White); // third

    spriteBatch.End();

    base.Draw(gameTime);
}//end Draw()
(适用于SpriteSortMode.Deferred)

另外,很抱歉谷歌翻译


哎呀。。。在回答之前,我没有更新评论

你在哪里绘制鼠标和播放器?将其编辑到你的问题中你确定你的鼠标位于地图的其余部分之上吗?从你发布的代码判断,它不应该超越,它位于玩家的顶部,玩家位于地图的顶部。当然,除了地图的右上角。我也试过做FrontToBack,但我看不出有什么不同。