Real-Time Strategy Game with Touch Screen

The availability of Ultrabook and Win 8 Tablets create a new frontier for PC gaming; one that brings touch and sensors inputs to parity with mouse and keyboard. New game genres are appearing that specifically leverage these input methods. The Real-Time Strategy (RTS) genre is one of the PC stalwarts. Though mouse and keyboard are the most precise input mechanisms available, all of the needed actions can be reasonably modeled by touch. This sample is a small RTS game which shows how touch inputs can be added alongside mouse and keyboard inputs for a full device input experience.

Controlling the sample

The controls summary is presented in the following table

One tap or left mouse button + move

Pan the view

Hold two taps + move or mouse wheel

Zoom In/Zoom Out

Hold three taps or right mouse button + move

Select units

Single tap or left mouse click

Move command

Double tap or double left mouse click

Attack command

Click/touch on the minimap

Move the camera to the specified point

Arrow keys

Pan the view

Page Up/Page Down

Zoom In / Zoom Out


The screen can be panned using left mouse button or one-tap touch. Minimap in the upper left corner shows the current camera location, object positions and the current view outline. The minimap also enables the user to quickly move the camera to any location by clicking on it with the left mouse button or one-tap touch. Arrow keys can also be used to pan the view.

The scene can be rendered with different zoom levels: from extreme close-up showing all details of every particular unit to strategic views showing almost all the battle scene.


The view can be zoomed in/out using mouse wheel or two-tap touch. Page Up / Page Down keys can also be used.

The sample enables the user to select one or more units using right mouse button or three-tap touch.

All units within the frame get selected. Selected units are marked with blue selection outline:

Selected units can be given move or attack commands. Move command for one or group of selected units is given by single left mouse button click or single touch on the terrain surface. After the command is given, the units start moving towards the designated point following the terrain surface.

Attack command is given with double left mouse click or double touch on the terrain surface point. After that, the selected units start attacking the point. After each explosion, the terrain at the point is slightly deformed and texture is updated.


Units at the point being attack are damaged. Each damage reduces the unit’s health which is indicated in the health bar rendered above the unit. Eventually the unit will be destroyed and explode creating a big hole in terrain surface.

Current command can be cancelled using the Stop button. All units in the scene can be selected using Select All button.

Some technical details 

  • WM_TOUCH is handled to respond to touch events
    • The sample keeps current input mode (like selection or scrolling) and switches between the modes depending on the user input
  • Basic collision detection between units is implemented using uniform grid:
    • The whole terrain is subdivided into the grid of equal-size square cells
    • Each grid cell supports a list of objects in this cell
    • When a unit is moved from one cell to another, the grid is updated accordingly
    • To check for a collision, each object’s bounding sphere is tested against all units in the object’s cell and its immediate neighbors
  • Each unit is rendered using one of the three levels of detail:
    • High-resolution geometric model for close-ups
    • Low-resolution geometric model for high point of view
    • Single sprite for very high points of view
    • The selection of the appropriate LOD is performed using estimated unit screen-space size
  • For terrain rendering, the method described in Touch Terrain sample is used
For more complete information about compiler optimizations, see our Optimization Notice.


Egor Yusov's picture

The best article on WM_TOUCH is perhaps MSDN. At least there you can find the most accurate information.
WM_TOUCH is a raw event. What it does is simply provides the coordinates of the touch points and some additional information (like if the point is down or up). The gesture recognition should be performed by the app. The sample shows one way to do this.

How difficult is it to add support for touch screen into existing games probably depends on the complexity of interaction with the user. If the mouse is the main input device for a game, then I could expect that it can be relatively easy to add support for touch.
At the same time, touch screen is a specific input device, which provides unique features like multi-touch, which a game can leverage to create a new user experience.

I also updated the archive to included the binaries as well.

Dmitry Oganezov's picture

Hi Egor! It's really cool!

Could you recommend some good articles on WM_TOUCH message?  I wonder what it takes to add WM_TOUCH support in already existed games.

BTW, could you please share the binaries together with the source code?

Add a Comment

Have a technical question? Visit our forums. Have site or software product issues? Contact support.