I'm a true beginner with using the android platform and I'm having difficulties on implementing a 2D grid system for a tower defense type game. Where I can place towers on a specific tile and enemies will be able to traverse through tiles etc.

What I would like is a practical explanation of how I could tackle this. A step by step guide for dummies.

This is what I believe are the necessary steps to take, I think I might be wrong but I hope someone could help me out.

  1. Calculate the Width and Height of the view I'm working with.
  2. Based on that, determine the number of tiles required and their dimensions, (Still not sure how I would do this)
  3. Create each tile as a Rectangle object and draw these rectangle on a canvas

I would really be grateful if someone could steer me in the right direction on how to implement a 2D Grid Map using android. I hope the answer to this questions helps the TRUE beginners out there like me.

I have looked at the following links below yet I still feel that I don't trully understand what's going on.

For XNA: 2D Grid based game - how should I draw grid lines?

How to Create a Grid for a 2D Game?

Also a quick note: All my previous game development has been in Java, mostly using Java SE and Swing. I also have good understanding of the game development process, it is only android thats confusing me :S

Update: I was actually able to implement, I have decided to post a link to a wiki-page of mine which I have started working on sometime back but not been able to progress further with it.

A simple solution to this can be found here: https://bitbucket.org/iadan/pathfinding/wiki/Home


2 Answers 2


I hope I help with the problem, though my solution might not answer exactly what you ask. I am not familiar with Swing, and usually my android development is done with Adobe Air. But by the powers of Google and my experience I shall try to help.

How to get the screen resolution using Java and Swing: https://stackoverflow.com/questions/3680221/screen-resolution-java

As for the number of tiles you need, that is a game design decision. For simplicity you can decide that all your levels will require a fixed tile size. Based on that you can then divide the screen width and height by the fixed number of tiles you require. So if the screen is 600 X 600 pixels and you require a 10 X 10 grid; each tile would be 60 X 60 pixels.

For added simplicity you could create the tiles at some arbitrary size and add them to the canvas and then scale the canvas to meet your screen size requirements.

Additionally you will want to take into account any UI elements you will have. Using the example above, if you decided to save 50 pixels around the border for UI elements, you would have 500 X 500 to work with making the tiles 50 X 50 pixels.


Take a look at Android SDK sample project Snake. It has TileView class which implements a 2D grid. If you have Android SDK on your computer, you can find it under .../android-sdk/samples/android-[api number]/Snake.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .