├── .gitignore ├── LICENSE ├── README.md ├── TiledSharp MonoGame Example.sln └── TiledSharp MonoGame Example ├── Content ├── Content.mgcb ├── exampleMap.tmx └── exampleTileset.png ├── Game1.cs ├── Icon.ico ├── Program.cs ├── Properties └── AssemblyInfo.cs └── TiledSharp MonoGame Example.csproj /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | build/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studo 2015 cache/options directory 26 | .vs/ 27 | 28 | # MSTest test Results 29 | [Tt]est[Rr]esult*/ 30 | [Bb]uild[Ll]og.* 31 | 32 | # NUNIT 33 | *.VisualState.xml 34 | TestResult.xml 35 | 36 | # Build Results of an ATL Project 37 | [Dd]ebugPS/ 38 | [Rr]eleasePS/ 39 | dlldata.c 40 | 41 | *_i.c 42 | *_p.c 43 | *_i.h 44 | *.ilk 45 | *.meta 46 | *.obj 47 | *.pch 48 | *.pdb 49 | *.pgc 50 | *.pgd 51 | *.rsp 52 | *.sbr 53 | *.tlb 54 | *.tli 55 | *.tlh 56 | *.tmp 57 | *.tmp_proj 58 | *.log 59 | *.vspscc 60 | *.vssscc 61 | .builds 62 | *.pidb 63 | *.svclog 64 | *.scc 65 | 66 | # Chutzpah Test files 67 | _Chutzpah* 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | *.cachefile 76 | 77 | # Visual Studio profiler 78 | *.psess 79 | *.vsp 80 | *.vspx 81 | 82 | # TFS 2012 Local Workspace 83 | $tf/ 84 | 85 | # Guidance Automation Toolkit 86 | *.gpState 87 | 88 | # ReSharper is a .NET coding add-in 89 | _ReSharper*/ 90 | *.[Rr]e[Ss]harper 91 | *.DotSettings.user 92 | 93 | # JustCode is a .NET coding addin-in 94 | .JustCode 95 | 96 | # TeamCity is a build add-in 97 | _TeamCity* 98 | 99 | # DotCover is a Code Coverage Tool 100 | *.dotCover 101 | 102 | # NCrunch 103 | _NCrunch_* 104 | .*crunch*.local.xml 105 | 106 | # MightyMoose 107 | *.mm.* 108 | AutoTest.Net/ 109 | 110 | # Web workbench (sass) 111 | .sass-cache/ 112 | 113 | # Installshield output folder 114 | [Ee]xpress/ 115 | 116 | # DocProject is a documentation generator add-in 117 | DocProject/buildhelp/ 118 | DocProject/Help/*.HxT 119 | DocProject/Help/*.HxC 120 | DocProject/Help/*.hhc 121 | DocProject/Help/*.hhk 122 | DocProject/Help/*.hhp 123 | DocProject/Help/Html2 124 | DocProject/Help/html 125 | 126 | # Click-Once directory 127 | publish/ 128 | 129 | # Publish Web Output 130 | *.[Pp]ublish.xml 131 | *.azurePubxml 132 | # TODO: Comment the next line if you want to checkin your web deploy settings 133 | # but database connection strings (with potential passwords) will be unencrypted 134 | *.pubxml 135 | *.publishproj 136 | 137 | # NuGet Packages 138 | *.nupkg 139 | # The packages folder can be ignored because of Package Restore 140 | **/packages/* 141 | # except build/, which is used as an MSBuild target. 142 | !**/packages/build/ 143 | # Uncomment if necessary however generally it will be regenerated when needed 144 | #!**/packages/repositories.config 145 | 146 | # Windows Azure Build Output 147 | csx/ 148 | *.build.csdef 149 | 150 | # Windows Store app package directory 151 | AppPackages/ 152 | 153 | # Others 154 | *.[Cc]ache 155 | ClientBin/ 156 | [Ss]tyle[Cc]op.* 157 | ~$* 158 | *~ 159 | *.dbmdl 160 | *.dbproj.schemaview 161 | *.pfx 162 | *.publishsettings 163 | node_modules/ 164 | bower_components/ 165 | 166 | # RIA/Silverlight projects 167 | Generated_Code/ 168 | 169 | # Backup & report files from converting an old project file 170 | # to a newer Visual Studio version. Backup files are not needed, 171 | # because we have git ;-) 172 | _UpgradeReport_Files/ 173 | Backup*/ 174 | UpgradeLog*.XML 175 | UpgradeLog*.htm 176 | 177 | # SQL Server files 178 | *.mdf 179 | *.ldf 180 | 181 | # Business Intelligence projects 182 | *.rdl.data 183 | *.bim.layout 184 | *.bim_*.settings 185 | 186 | # Microsoft Fakes 187 | FakesAssemblies/ 188 | 189 | # Node.js Tools for Visual Studio 190 | .ntvs_analysis.dat 191 | 192 | # Visual Studio 6 build log 193 | *.plg 194 | 195 | # Visual Studio 6 workspace options file 196 | *.opt 197 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Temeez 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Check the [Newer example that works with MonoGame 3.8](https://github.com/Temeez/TiledCS-MonoGame-Example). 2 | 3 | # [TiledSharp](https://github.com/marshallward/TiledSharp) [MonoGame](https://github.com/mono/MonoGame) Example 4 | 5 | This example shows how simple it is to draw a (TMX) map made with [Tiled](http://www.mapeditor.org/) in MonoGame project. 6 | 7 | ## Note: 8 | Remember to add TileSharp to your projects **References**! 9 | 10 | The (TMX) map file is **not** supposed to be build with content pipeline. Just add it to the project and set **Copy if newer** from the files properties. 11 | 12 | -------------------------------------------------------------------------------- /TiledSharp MonoGame Example.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.31101.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TiledSharp MonoGame Example", "TiledSharp MonoGame Example\TiledSharp MonoGame Example.csproj", "{B8D94813-4912-40DB-8C02-0C042E591FA5}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x86 = Debug|x86 11 | Release|x86 = Release|x86 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {B8D94813-4912-40DB-8C02-0C042E591FA5}.Debug|x86.ActiveCfg = Debug|x86 15 | {B8D94813-4912-40DB-8C02-0C042E591FA5}.Debug|x86.Build.0 = Debug|x86 16 | {B8D94813-4912-40DB-8C02-0C042E591FA5}.Release|x86.ActiveCfg = Release|x86 17 | {B8D94813-4912-40DB-8C02-0C042E591FA5}.Release|x86.Build.0 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /TiledSharp MonoGame Example/Content/Content.mgcb: -------------------------------------------------------------------------------- 1 | 2 | #----------------------------- Global Properties ----------------------------# 3 | 4 | /outputDir:bin/WindowsGL 5 | /intermediateDir:obj/WindowsGL 6 | /platform:WindowsGL 7 | /config: 8 | /profile:Reach 9 | /compress:False 10 | 11 | #-------------------------------- References --------------------------------# 12 | 13 | 14 | #---------------------------------- Content ---------------------------------# 15 | 16 | #begin exampleTileset.png 17 | /importer:TextureImporter 18 | /processor:TextureProcessor 19 | /processorParam:ColorKeyColor=255,0,255,255 20 | /processorParam:ColorKeyEnabled=True 21 | /processorParam:GenerateMipmaps=False 22 | /processorParam:PremultiplyAlpha=True 23 | /processorParam:ResizeToPowerOfTwo=False 24 | /processorParam:TextureFormat=Color 25 | /build:exampleTileset.png 26 | 27 | -------------------------------------------------------------------------------- /TiledSharp MonoGame Example/Content/exampleMap.tmx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | eJxjZmBgYKQAwwALDjaMjy6PrgafOD55RiRxdAySY4KymdAwTAwALGwAaQ== 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /TiledSharp MonoGame Example/Content/exampleTileset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NaakkaDev/TiledSharp-MonoGame-Example/2f0c6843cb33a2ebee68adf44c5eb7fc123f2415/TiledSharp MonoGame Example/Content/exampleTileset.png -------------------------------------------------------------------------------- /TiledSharp MonoGame Example/Game1.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | using Microsoft.Xna.Framework.Graphics; 3 | using Microsoft.Xna.Framework.Input; 4 | using System; 5 | using TiledSharp; 6 | 7 | namespace TiledSharp_MonoGame_Example 8 | { 9 | /// 10 | /// This is the main type for your game. 11 | /// 12 | public class Game1 : Game 13 | { 14 | GraphicsDeviceManager graphics; 15 | SpriteBatch spriteBatch; 16 | 17 | TmxMap map; 18 | Texture2D tileset; 19 | 20 | int tileWidth; 21 | int tileHeight; 22 | int tilesetTilesWide; 23 | int tilesetTilesHigh; 24 | 25 | public Game1() 26 | { 27 | graphics = new GraphicsDeviceManager(this); 28 | Content.RootDirectory = "Content"; 29 | } 30 | 31 | /// 32 | /// Allows the game to perform any initialization it needs to before starting to run. 33 | /// This is where it can query for any required services and load any non-graphic 34 | /// related content. Calling base.Initialize will enumerate through any components 35 | /// and initialize them as well. 36 | /// 37 | protected override void Initialize() 38 | { 39 | // TODO: Add your initialization logic here 40 | 41 | base.Initialize(); 42 | } 43 | 44 | /// 45 | /// LoadContent will be called once per game and is the place to load 46 | /// all of your content. 47 | /// 48 | protected override void LoadContent() 49 | { 50 | // Create a new SpriteBatch, which can be used to draw textures. 51 | spriteBatch = new SpriteBatch(GraphicsDevice); 52 | 53 | map = new TmxMap("Content/exampleMap.tmx"); 54 | tileset = Content.Load(map.Tilesets[0].Name.ToString()); 55 | 56 | tileWidth = map.Tilesets[0].TileWidth; 57 | tileHeight = map.Tilesets[0].TileHeight; 58 | 59 | tilesetTilesWide = tileset.Width / tileWidth; 60 | tilesetTilesHigh = tileset.Height / tileHeight; 61 | } 62 | 63 | /// 64 | /// UnloadContent will be called once per game and is the place to unload 65 | /// game-specific content. 66 | /// 67 | protected override void UnloadContent() 68 | { 69 | // TODO: Unload any non ContentManager content here 70 | } 71 | 72 | /// 73 | /// Allows the game to run logic such as updating the world, 74 | /// checking for collisions, gathering input, and playing audio. 75 | /// 76 | /// Provides a snapshot of timing values. 77 | protected override void Update(GameTime gameTime) 78 | { 79 | if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) 80 | Exit(); 81 | 82 | base.Update(gameTime); 83 | } 84 | 85 | /// 86 | /// This is called when the game should draw itself. 87 | /// 88 | /// Provides a snapshot of timing values. 89 | protected override void Draw(GameTime gameTime) 90 | { 91 | GraphicsDevice.Clear(Color.CornflowerBlue); 92 | 93 | spriteBatch.Begin(); 94 | 95 | for (var i = 0; i < map.Layers[0].Tiles.Count; i++) { 96 | int gid = map.Layers[0].Tiles[i].Gid; 97 | 98 | // Empty tile, do nothing 99 | if (gid == 0) { 100 | 101 | } 102 | else { 103 | int tileFrame = gid - 1; 104 | int column = tileFrame % tilesetTilesWide; 105 | int row = (int)Math.Floor((double)tileFrame / (double)tilesetTilesWide); 106 | 107 | float x = (i % map.Width) * map.TileWidth; 108 | float y = (float)Math.Floor(i / (double)map.Width) * map.TileHeight; 109 | 110 | Rectangle tilesetRec = new Rectangle(tileWidth * column, tileHeight * row, tileWidth, tileHeight); 111 | 112 | spriteBatch.Draw(tileset, new Rectangle((int)x, (int)y, tileWidth, tileHeight), tilesetRec, Color.White); 113 | } 114 | } 115 | 116 | spriteBatch.End(); 117 | 118 | base.Draw(gameTime); 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /TiledSharp MonoGame Example/Icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NaakkaDev/TiledSharp-MonoGame-Example/2f0c6843cb33a2ebee68adf44c5eb7fc123f2415/TiledSharp MonoGame Example/Icon.ico -------------------------------------------------------------------------------- /TiledSharp MonoGame Example/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TiledSharp_MonoGame_Example 4 | { 5 | #if WINDOWS || LINUX 6 | /// 7 | /// The main class. 8 | /// 9 | public static class Program 10 | { 11 | /// 12 | /// The main entry point for the application. 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | using (var game = new Game1()) 18 | game.Run(); 19 | } 20 | } 21 | #endif 22 | } 23 | -------------------------------------------------------------------------------- /TiledSharp MonoGame Example/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("TiledSharp MonoGame Example")] 9 | [assembly: AssemblyProduct("TiledSharp MonoGame Example")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("6e67acc3-b589-44ad-b424-7e6120d8918b")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("3.4.0.312")] 36 | [assembly: AssemblyFileVersion("3.4.0.312")] 37 | -------------------------------------------------------------------------------- /TiledSharp MonoGame Example/TiledSharp MonoGame Example.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | x86 6 | 8.0.30703 7 | 2.0 8 | {B8D94813-4912-40DB-8C02-0C042E591FA5} 9 | WinExe 10 | Properties 11 | TiledSharp_MonoGame_Example 12 | TiledSharp MonoGame Example 13 | 512 14 | WindowsGL 15 | 16 | 17 | 18 | 19 | x86 20 | true 21 | full 22 | false 23 | bin\WindowsGL\Debug\ 24 | DEBUG;TRACE;WINDOWS 25 | prompt 26 | 4 27 | 28 | 29 | x86 30 | pdbonly 31 | true 32 | bin\WindowsGL\Release\ 33 | TRACE;WINDOWS 34 | prompt 35 | 4 36 | 37 | 38 | Icon.ico 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | $(MSBuildProgramFiles32)\MonoGame\v3.0\Assemblies\WindowsGL\OpenTK.dll 48 | 49 | 50 | $(MSBuildProgramFiles32)\MonoGame\v3.0\Assemblies\WindowsGL\MonoGame.Framework.dll 51 | 52 | 53 | 54 | 55 | ..\..\..\Libraries\TiledSharp.dll 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | PreserveNewest 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 84 | --------------------------------------------------------------------------------