MonoGame renderTarget2D错误

时间:2015-03-14 11:17:31

标签: c# runtime-error monogame

我开始游戏并且一切正常但是在大约15次seconts之后游戏崩溃并且我得到了这个错误:

enter image description here

错误:

附加图像的内部格式组合违反了依赖于实现的一组限制。

这是我的代码:

using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using System.Collections.Generic;

namespace TileMap
{
public class Map
{
    List<Texture2D> tileTextures;

    Texture2D map;

    RenderTarget2D renderTarget2d;

    int tileSize;

    Vector2 scale;

    int[,] mapData;


    public Map()
    {
        tileTextures = new List<Texture2D> ();

        tileSize = 64;

        scale = new Vector2(8, 8);

        mapData = new int[,]
        {
            {2,2,2,2,2},
            {1,1,1,1,1},
            {1,1,1,1,1},
            {1,1,1,1,1},
            {1,1,1,1,1},
        };
    }

    public void setTiles(Texture2D Air, Texture2D Dirt, Texture2D Grass)
    {
        /* index : 0 */ tileTextures.Add (Air);
        /* index : 1 */ tileTextures.Add (Dirt);
        /* index : 2 */ tileTextures.Add (Grass);  
    }

    public Texture2D getMap()
    {
        return map;
    }

    public void MakeMap(SpriteBatch spriteBatch, GraphicsDevice graphicsDevice)
    {
        renderTarget2d = new RenderTarget2D(graphicsDevice, 1281, 721);
        graphicsDevice.SetRenderTarget(renderTarget2d);

        spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null);

        graphicsDevice.Clear(Color.DarkBlue);

        for (int y = 0; y < mapData.GetLength (0); y++) 
        {
            for (int x = 0; x < mapData.GetLength (1); x++) 
            {
                int index = mapData [y, x];
                Texture2D texture = tileTextures[index];

                spriteBatch.Draw(texture, new Vector2(x * tileSize + 1, y * tileSize + 1), null, Color.White, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f);
            }
        }

        spriteBatch.End();


        graphicsDevice.SetRenderTarget(null);

        map = renderTarget2d;
    }
}
}

我在Game1类中的每次绘制调用中调用MapMap方法。 我怎样才能摆脱错误以及导致错误的原因?

1 个答案:

答案 0 :(得分:0)

RenderTarget2D的分辨率可能是个问题。

我注意到在使用SharpDX时这需要是4的倍数,但我找不到任何文档来备份它。

尝试使用1280x720而不是1281x721。