Philosophical Ranting of an Engineer

Fun With Tiles

April 6th, 2007

This blog may or may not turn into “fun and exciting experiences Matthew had while writing his game.”

My engine is coming along nicely. It loads and draws a map and can draw units. I was doing some refactoring because the TileEngine class was responsible for loading the Map and I thought the World class should be doing that. So changed some code so it was the World that created the map and then passed it to the TileEngine for rendering. Lo and behold once I got it compiled and ran it I was displayed a beautiful blue screen, which is the background color. No tiles! I was very distraught as there were no exceptions to trace and no null variables I could locate. I had no idea why it was no longer drawing my game.

And then I remembered two little lines of code that I had deleted and forgotten to replace.

myWorld.Map.TileHeight = 48; myWorld.Map.TileWidth = 48;

These numbers specify the number of pixels in every tile of the map. These variables are used everywhere in my rendering engine. It uses it to specify the size of the tiles; it uses it to determine where to draw units. I had forgotten to set these values and thus they were the default C# value: 0.

Behold, my rendering engine was working properly! Only it was drawing all the tiles with 0 height and 0 width. It was drawing and infinitely small map. I added the lines back in and everything worked.

1 Response to “Fun With Tiles”

  1. Darkell Says:
    Don't forget those code lines!

Sorry, comments are closed for this article.