I can’t get MonoGame.Extended.Tiled to work. I followed this sample.
Here are the steps to reproduce the error:
I create a new MonoGame CrossPlatform Desktop Project (MonoGame version 3.6) in Visual Studio (2015).
I install the MonoGame.Extended packages (latest stable release 0.6.377) via NuGet.
I follow the sample code.
// I add these members to the template
private Camera2D camera;
private TiledMap map;
private TiledMapRenderer mapRenderer;
// I add this code to LoadContent
var viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
camera = new Camera2D(viewportAdapter);
// I created a map named "level" (see images), added it to the Content Pipeline - successful build
// Naturally I also added the necessary tileset ("PokemonTiles.png") with the default Texture Importer
map = Content.Load<TiledMap>("level");
mapRenderer = new TiledMapRenderer(GraphicsDevice);
// I add this to Draw
var viewMatrix = camera.GetViewMatrix();
var projectionMatrix = Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.Viewport.Width,
GraphicsDevice.Viewport.Height, 0, 0f, -1f);
mapRenderer.Draw(map, ref viewMatrix, ref projectionMatrix);
There are 2 problems with this image. First, the wrong tiles are rendered. Second, for some reason the transparent part of these incorrect tiles is filled with the color black.
Here is how it should look like:
Can you try pre-release packages and see if still is a problem?
The transparent part of the texture is set by the ColorKey property in the content builder for the texture.
I tried multiple versions, older and newer ones, but neither of them worked.
No success with the transparency either - the problematic tiles already contain a transparent background, the ColorKey processor parameter only makes those parts of the tiles transparent that are correctly rendered (when I set the color to brown, for example, the - parts of the - fences disappear, meaning they become black as well).
Found the problem. You are missing a columns XML attribute on the tileset XML element. I discovered this by opening the map in Tiled and saving it again. The following map works:
Yes, you need to set the render state to AlphaBlend: GraphicsDevice.BlendState = BlendState.AlphaBlend.
The TiledMapRenderer does not apply states for you because there is no “begin” and “end”, just “draw”. You can also draw on a layer by layer basis. So for example in classic RPG Maker 2000 and up there is a “ground”, “mask”, and “fringe” layers. The “ground” layer would use BlendState.Opaque and would be drawn below the player and all enitites / game objects; it has tiles with no transparency. The “mask” layer would use BlendState.AlphaBlend and would be drawn below the player and all entities / game objects; it can have tiles with transparency. The “fringe” layer also uses BlendState.AlphaBlend and would be drawn above the player and all entities / game objects. This kind of rendering scheme is called Painter’s Algorithm and is suitable for rendering Tiled maps for a top down game.