How To Play?

Here’s a little on how some in-game controls and overlays work.

After we had the tiled map up and running, we thought about how the controls would work. Most of the TD games we’ve played had a pointer since it’s either on the PC or Xbox 360, so how would this work with a touch screen? Hmmm.

Following the same train of thought about dealing with player experience, we realized the necessity of a HUD (Heads-Up Display) as well. The player need to know how much health and coins they have, what wave of enemies they’re at, etc. We needed a system to deal with that as well.

With the controls, we finally decided on a familiar design that uses a stationary cursor.

The cursor is operated by tapping on any tile once, which brings up the tower building menu. Depending on the location of the tile selected, the building menu appears either on top or on the bottom of the screen. Selection of a tile can be cancelled by tapping the same tile again. This will remove the building menu for an unobstructed view of the map.

When this was first implemented, we ran into problems with the cursor rapidly blinking on and off; due to our design of the selection cancellation mechanism. After playing around with the code a bit, we decided on building a buffer to dull down the sensitivity of a tap with respect to time. This allowed for the tap time (touch down event) to be in the “normal” range; thus allowing the selection cancellation to function as we intended.

And here we have our tick method of the TileScreen class:

public void tick (Input input) {
	if (Gdx.input.isTouched()) {
		pixelX = Gdx.input.getX();
		pixelY = Gdx.input.getY();
		if (input.buttons[0] == true) {
			buffer += 1.0f / 60.0f;
		operateCursor = false;
	else {
		if (input.buttons[0] == false && input.oldButtons[0] == true) {
			if (buffer < 0.24f) {
				if (selected) {
					operateCursor = false;
					operateBuildMenu = true;
					touched = true;
				else {
					operateCursor = true;
					touched = true;
			else {
				touched = false;
			buffer = 0;
	// Comment out the following line to untame the FPS

The variables operateCursor, operateBuildMenu, and touched are boolean variables that help to differentiate a few different states of input within our code. Gdx.input.isTouched() from the libgdx package becomes true when a touchdown event happens. Just to make sure that the input event is a “touch down” instead of a “touch up”, the buffer only increments when the input.buttons[0] == true (input.buttons[] is an array holding the most recently entered keys).

Each call on tick will add 0.0166 (1/60) to the buffer; when the buffer reaches 0.24, the cursor will stop operating and the tower building menu comes up. Afterwards, the buffer is reset to 0. What this does is it effectively allows “a touch down” to be approximately a quarter of a second.

More on the tower building menu and the HUD next post.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: