Clone wiki

XTiled / Home

Welcome

XTiled is a C#/XNA library for importing TMX maps created in Tiled Map Editor. The library supports orthogonal and isometric map formats as well as all TMX 0.8.1 map features and has runtime components for PC and Xbox 360.

Project issues and feature requests are kept in the Issues section of Bitbucket. Questions can be asked on the XTiled discussion Google Group.

Video showing some of the features of XTiled: http://www.youtube.com/watch?v=qd0Yh50SPL4

Documentation

Getting Started

Download the lastest version of XTiled from the Downloads section and unzip the files somewhere on your hard drive. This can be inside your solution folder if you wish.

Right-click your Content project and select 'Add Reference...', and use the 'Browse' tab to find the file named FuncWorks.XNA.XTiledExtensions.dll you downloaded above.

Right-click your Game project and select 'Add Reference...', and use the 'Browse' tab to find the file named FuncWorks.XNA.XTiled.dll you downloaded above for the platform target (Windows or Xbox 360) of your game.

Add your *.tmx filed created in the Tiled Map Editor to your content project.

Copy all images used in your *.tmx file to the same directory as the *.tmx file in the content project. Be sure to keep the same folder structure (i.e. if you put your images in a subdirectory below the *.tmx file, keep this subdirectory).

Note: It is not required that you add the images to your content project, by default XTiled will include them automatically.

Once you have the Tiled map in your content project, add this using statement to your game code: "using FuncWorks.XNA.XTiled;"

The following example shows how to load a map named "desert.tmx", move around with the arrow keys, and render the map:

using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using FuncWorks.XNA.XTiled;

namespace TestGame {
    public class Game1 : Microsoft.Xna.Framework.Game {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        Rectangle mapView;
        Map map;

        public Game1() {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize() {
            base.Initialize();
            mapView = graphics.GraphicsDevice.Viewport.Bounds;
        }

        protected override void LoadContent() {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            map = Content.Load<Map>("desert");
        }

        protected override void Update(GameTime gameTime) {
            KeyboardState keys = Keyboard.GetState();

            if (keys.IsKeyDown(Keys.Escape))
                this.Exit();

            Rectangle delta = mapView;
            if (keys.IsKeyDown(Keys.Down))
                delta.Y += Convert.ToInt32(gameTime.ElapsedGameTime.TotalMilliseconds / 4);
            if (keys.IsKeyDown(Keys.Up))
                delta.Y -= Convert.ToInt32(gameTime.ElapsedGameTime.TotalMilliseconds / 4);
            if (keys.IsKeyDown(Keys.Right))
                delta.X += Convert.ToInt32(gameTime.ElapsedGameTime.TotalMilliseconds / 4);
            if (keys.IsKeyDown(Keys.Left))
                delta.X -= Convert.ToInt32(gameTime.ElapsedGameTime.TotalMilliseconds / 4);

            if (map.Bounds.Contains(delta))
                mapView = delta;

            base.Update(gameTime);
        }

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

            spriteBatch.Begin();
            map.Draw(spriteBatch, mapView);
            spriteBatch.End();

            base.Draw(gameTime);
        }

    }
}

Updated