xTile Tutorial for XNA Game Studio 4.0
This is a short tutorial explaining how to get started with the xTile tiling engine using XNA Game Studio 4.0. By the end of this tutorial you should have a working XNA 4.0 game application for Windows featuring a parallax scrolling
1. Start Visual Studio 2010 and create a new XNA Windows Game (4.0) project and name it xTileGame1.
2. Using the Solution Explorer panel, create a new solution folder named xTile directly under the solution. Also create a corresponding xTile folder on disk
within the xTileGame1 solution folder.
3. Copy the xTile.dll (PC version) and xTile.Pipeline.dll assemblies from the downloaded xTile Engine ZIP archive into the xTile solution folder created previously.
Add the assemblies as existing items under the xTile folder in Solution Explorer.
4. Add an xTile.dll reference to the xTileGame1 project.
5. Add an xTile.Pipeline.dll reference to the xTileGame1Content content project of the xTileGame1 project (not the game project itself).
6. Add a tIDE map file and its associated tile sheet images in the
xTileGame1Content content project. Create content folders as necessary to maintain relative path references from the map file to the tile sheet image sources. Ensure that the map file's Content Importer and Content
Processor properties are set respectively to tIDE Map Importer and tIDE Map Processor. Also ensure that the Build Action property of the tile sheet image files referred
by the map file is set to None to avoid conflicts with the map's content processor.
7. Compile the project and verify that the tIDE map file is being correctly processed by the content pipeline.
8. Access the code file Game1.cs and add the following using clauses for the xTile engine:
9. Add member variables for an xTile map, display device and viewport:
10. Within the Initialize() method, instantiate the map display device, load the map resources and set a display viewport:
11. Within the LoadContent() method, load the map from the content pipeline:
12. Within the Update(GameTime gameTime) method, update the map for tile animation and update the viewport for level scrolling:
13. Within the Draw(GameTime gameTime) method, render the map visually using the display device and viewport:
14. Compile and run the xTileGame1 project.
Note for Visual Studio Express Users
Solution folders are not supported in the Express edition of Visual Studio. In this case, you may place the assemblies in project folders or simply opt out from adding them as project items.