Skip to content

Instantly share code, notes, and snippets.

@Langerz82
Created October 19, 2016 19:46
Show Gist options
  • Save Langerz82/62e9437cd7f733e254c0973548b6afd6 to your computer and use it in GitHub Desktop.
Save Langerz82/62e9437cd7f733e254c0973548b6afd6 to your computer and use it in GitHub Desktop.
debugging
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Diagnostics;
using System.IO;
using TiledSharp;
namespace Game1
{
/// <summary>
/// This is the main type for your game.
/// </summary>
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
//TmxMap map;
//Texture2D tileset;
int tileWidth;
int tileHeight;
int tilesetTilesWide;
int tilesetTilesHigh;
int tilesWidth = 28;
int tilesHeight = 18;
int tilesOffsetX = 0;
int tilesOffsetY = 0;
bool movingDown = false;
bool movingUp = false;
bool movingLeft = false;
bool movingRight = false;
static int SCALE = 3;
string mapPath;
bool loadingMap = false;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
graphics.PreferredBackBufferWidth = tilesWidth * 16 * SCALE; // set this value to the desired width of your window
graphics.PreferredBackBufferHeight = tilesHeight * 16 * SCALE; // set this value to the desired height of your window
graphics.ApplyChanges();
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
}
public static string GetAssetPath(string mapFilename)
{
//var assembly = Assembly.GetAssembly(typeof(TiledSharpTest));
var rootPath = "C:\\Users\\joslan\\Documents\\Visual Studio 2015\\Projects\\TiledSharp\\assets";
var mapPath = Path.Combine(rootPath.ToString(), mapFilename);
return mapPath;
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
try
{
mapPath = GetAssetPath("minimal.tmx");
//TmxMap map = new TmxMap(mapPath);
//TmxMap map = new TmxMap("Content\\minimal.tmx");
//map = new TmxMap("");
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
//tileset = Content.Load<Texture2D>(map.Tilesets[0].Name.ToString());
//tileWidth = map.Tilesets[0].TileWidth;
//tileHeight = map.Tilesets[0].TileHeight;
//tilesetTilesWide = tileset.Width / tileWidth;
//tilesetTilesHigh = tileset.Height / tileHeight;
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// game-specific content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// TODO: Add your update logic here
if (!loadingMap)
{
//TmxMap map = new TmxMap(mapPath);
TmxLayer layer = new TmxLayer(null, 0, 0);
loadingMap = true;
}
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
base.Draw(gameTime);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment