Isometric Map in SFML
isometric rpg 2D SFML
In my ever-so-humble opinion, "traditional" 2D isometric games (ie, games implemented using only 2D techniques to fake an isometric viewpoint) are as dead as last week's meatloaf. Traditional techniques present a number of problems that are solved by hacks and kludges, but which are solved much more elegantly via a 3D approach. Nevertheless, when someone is just starting out with game programming, 3D can be intimidating. Also, maybe you're looking to go retro, and while 3D can benefit even a retro style, still it might be more feasible to implement a traditional 2D system. I personally rarely use traditional 2D in my own projects anymore, but I found this on my hard-drive and updated it. The system is based on the original 2D system upon which I built my older game, Golem, albeit modified to work with SFML.
Presented here is an example of how you might go about implementing a traditional 2D isometric map using SFML. I chuckle as I write this, since SFML is just a 2D front-end sitting on top of OpenGL which is, of course, a 3D API. Nevertheless, SFML is implemented to be a 2D library, and so it might be nice to have an isometric map system that works with SFML without having to delve into OpenGL.
At the end of this article, we will have a working 2D isometric map of arbitrary size, with a basic tile-based lighting scheme, suitable for some sort of graphical roguelike or other 2D RPG-type game. I will provide all of the code, and a working demo. I will discuss the structure of the map, the organization of the lighting scheme, how it all fits together with SFML. I will also touch on a few of the issues and caveats that crop up when using an old-school 2D system, and why using 3D makes things so much easier.
To see what we are shooting for, here are a couple screenshots of the final product:
Now, I explain in the remainder of this post how the system works. If you don't care, already know enough about isometric maps, etc... and just want to get to the code, here is the archive:
Included is all the source, including source to bind SFML to Lua, the isometric map code presented here, and a small sample Lua application demonstrating the system. Tinker to your heart's content. Be warned, though, that this has been sitting on my harddrive mostly untouched for a couple years now, and there might be bugs a-lurking. Since it's not code I commonly use, it hasn't been very thoroughly tested.