2D Tile Maps – Tile Picking

Several months ago, I talked about the distinction between world space and screen space. As a recap, these are fundamental concepts that separate our game or simulation state from our drawn or rendered state. What gets drawn to the screen is not necessarily how things are laid out in the game’s actual (world) state. Check out the previous articles for more information.

The concept of tile picking involves a user hovering their mouse or some other input device over a tile in the game map. Usually the user is doing this in order to interact with the tile such as moving a unit to a location, placing an item on the tile, or inspecting the metadata of the tile. Fortunately for the developer, the process of picking is independent of the projection other than some simple math to do a conversion of coordinates.

Imagine that you are playing SimCity 2000, and you want to create a stretch of road from one location to another. The process involves the user hovering the starting tile, clicking the mouse, dragging the road to the end tile, and releasing the mouse. Tiles were picked out of the game map based on the mouse’s coordinates during game updates. Which space do we pick the tile from? Do we have to calculate if the mouse is contained within the projected tile or within the game’s world space coordinates?

Orthogonal

If the projection used in the game is orthogonal (think NES/SNES Zelda games), then the tile picking really is just a matter of answering the question, “Which tile contains the current mouse coordinate?” Answering the question is simple:

2D Tile Maps – World and Screen Spaces

If you are not familiar with tile maps, please see the previous article in this series before reading this article.

Spaaaaaaace!

A space is simply some collection of points, vectors, shapes, and other objects that we use to store the state of our game or simulation. There are various kinds of spaces that can be employed during game development, but the two that I will focus on for this article are the concepts of world spaces and screen spaces. It is important to know the distinction and differences between these two spaces because it will make your game development journey much clearer and easier. Personally, it took me awhile before the concept of separating the spaces really “clicked” for me.

World Space

The most commonly understood space is the world space of the game. This is the space that contains the positions of all entities in the game. For example, if we have a 5 x 5 tile map where each tile is 16 x 16, worldspacewe can represent that map (as discovered in the previous article) as a two dimensional array where [0, 0] is the first tile and [5, 5] is the last tile. Where these tiles are drawn on screen is of no importance when you generate the tile indices in the representative array. The underlying world of your game is represented by this array. The entities live their lives in this boring, mundane, grid-like existence.

All the game interactions and logic take place within this world space because of how extremely simple and efficient it is to perform calculations if we assume our game is as simple as an evenly laid out grid.… Continue reading

Introducing the Steam Community Viewer

In my free time, I’ve been developing a Windows 8 app to view Steam-related information (news, deals, community profiles). I just got notification that my new app was approved and listed on the Windows 8 store.

You can search for it directly in the Windows Store or see it online.

A brief description of the app is below:

The Steam Community Viewer allows users to search for Steam Community profiles to view profile details, game lists, game statistics, achievements, friend lists, group lists, and more. All data is obtained through public and Valve supplied methods. This application is not associated with Valve Software.

This is just a first release, but I’m hoping to add a lot more functionality as I continue to develop it.

Make sure to use the support email address listed in the store if you need any assistance. Additionally, you can tweet me @babelshift.… Continue reading

Read about My Game: The Chains of Acadia

I have been developing software professionally for about 5 years now, and I have been playing video games nearly my entire life. The combination of the two is something that I decided to tackle back in July of this year. Having never programmed for anything other than enterprise software, I decided to ease my way into the scene via XNA. I was already familiar with C# through my work, so it was an obvious choice to learn the basics and dip my toes into the ocean of game design.

Since I am a full-time employee, I usually only get nights and weekends to work on this project. I would love to dedicate all my time to the development of my first game, but I am constantly reminded that something has to pay the bills. Anyway, you did not come here to read about my life; you came to read about my game! I have quickly learned that game development calls for many different talents. Some of the requirements include skills that I simply do not possess. Namely, I have trouble producing quality art, sound, and music. Since I am in this alone (for now), I have to rely on the wonderful open source community to fill this important gap. I can handle the technical side no problem, but when it comes to art, yikes. Without further ado, here is my game.

The Chains of Acadia is a story of a hero. Oh, wow, how original. The thing is though, Acadia (the hero), does not know that he is a hero.… Continue reading

Quirks with XNA ContentManager Load and Unload

I was recently experimenting with game state transitions and attempting to unload content when a screen was no longer needed. For example, I had a main menu screen which loaded assets to its own ContentManager on activation and unloaded the content when the screen transitioned off based on user input. This all worked fine until the main menu was asked to transition back on after the user was done playing the game.

What I found is that calling the ContentManager’s Unload method will call the Dispose method of all the resources for which it is responsible. You do not and should not manually call the Dispose method for content that has been loaded. However, a problem arises when you want to reuse something that has been unloaded without reinitializing the ContentManager. Even worse, the problem arises even if you call the Load method for a piece of content after it has been Unloaded.

For example:

I received an error on line 7 of the above paste because even though I reloaded the texture, the ContentManager will return the cached version of the already loaded texture (even though you called Unload!).… Continue reading

Build XNA Game Installer: Visual Studio Setup Project

This guide assumes:

  • Visual Studio 2010 Professional
  • XNA Game Studio 4.0
  • Users will be Windows

This is the second article about building an XNA game installer when you are ready to distribute your game to the masses. In the first part, I described how to use the convenient ClickOnce option to build a relatively simple and non-customizable deployment package. If the ClickOnce option is too restrictive for you or simply does not meet your needs then you should refer to this article about using a Setup Project to create a more customizable installation package.

As with most things in life, the Setup Project is not a perfect solution to packaging up and distributing your game. What I find extremely annoying and shortsighted on Microsoft’s part is that the Setup Project will not automatically detect your game content like ClickOnce does. I want to be clear that, in this context, “content” is referring to your compiled content by the Content Pipeline (textures, sounds, other files) and not the “content” of your project as a whole. I will explain how to force the Setup Project to use your game content. Be warned: it is tedious and annoying, but it works..

  1. Open your game solution
  2. Right click solution -> Add -> New Project…
  3. Other Project Types -> Setup and Deployment -> Visual Studio Installer -> Setup Project
  4. Right click the setup project -> Properties
  5. Change the “Configuration” drop down to whatever configuration you want the setup to use (debug/release/etc)
  6. Click “prerequisites”
  7. Make sure these are checked:
    • Microsoft .NET Framework 4 Client Profile (x86 and x64)
    • Microsoft XNA Framework Redistributable 4.0
    • Windows Installer 3.1
  8. Right click the setup project -> View -> File System
  9. In the “Application Folder”, right click -> Add -> Project Output
  10. Change the “Project” drop down to the main game project
  11. Click “Primary” output in the list box
  12. Choose the configuration for which you want to include the output (debug/release/etc)
  13. Repeat steps 9-12 for any other projects that you need to include in the output (custom libraries)
    • NOTE: Do note include output from content pipeline extension projects because the content pipeline it is unavailable at run time

You just created a setup project, told it which prerequisites are needed for your game to work, and finally told it which build output you want to include in the installer.… Continue reading

Build XNA Game Installer: ClickOnce

This guide assumes:

  • Visual Studio 2010 Professional
  • XNA Game Studio 4.0
  • Users will be Windows

This article is the first of two on how to package your XNA game into an installer for Windows environments. The first is the easier but less customizable option of using Visual Studio’s built in ClickOnce installer. ClickOnce is essentially a hand-holding tool to package up prerequisites, dependencies, manifests, and content. Additionally, it allows you to specify locations from which the users will install the package (CD, Web, Shared Drive). More conveniently, ClickOnce allows you to specify where the application should check for updates in order to automatically update the content when new versions of the application are released. For example, you could specify a URL that the application will use to check for new versions. If a new version is detected, you can specify either the same URL or a different URL to use for downloading the new content.

While ClickOnce is easy to use, it is not perfect for every scenario and can fail quite spectacularly. I have personally run into situations where users could not install updates to the application because of cryptic errors that were only resolved by completely recreating a user account in Windows (I kid you not, this is a Microsoft-sanctioned approach). Many of the errors are difficult to diagnose and the documentation does not help much when it comes to the more advanced features of ClickOnce. It is definitely convenient, but do not use it if you want customization or extendability.… Continue reading