Game Development Reference
In-Depth Information
Finally, each tile is rendered with the
DrawTile()
method call:
for ( int i = 0; i != g->FColumns; i++ )
for ( int j = 0; j != g->FRows; j++ )
DrawTile( g, i, j, Color );
}
The
DrawTile()
method calculates the coordinates of the tile in normalized screen
coordinates
(0...1)
and uses a rectangular vertex array and the
g_Canvas
object to render
the
Tile
instance:
void DrawTile( clPuzzle* g, int i, int j, const vec4& Color )
{
if ( i < 0 || j < 0 || i >= g->FColumns || j >= g->FRows )
{ return; }
clTile* Tile = g->GetTile( i, j );
Tile->SetTarget( i, j );
float X = Tile->FCur.x;
float Y = Tile->FCur.y;
float TW = 1.0f / g->FColumns;
float TH = 1.0f / g->FRows;
vec4 TilePosition(
TW * ( X + 0 ), TH * ( Y + 0 ),
TW * ( X + 1 ), TH * ( Y + 1 ) );
g_Canvas->TexturedRectTiled(
TilePosition, 1.0f, 1.0f, g_Texture,
Effect, Color, VA, Tile->GetRect() );
}
In the next recipes, we combine this simple gameplay with an animated image selector and
the Picasa images downloader to create a more feature-rich puzzle game.
Implementing the animated 3D image
selector
The main UI element of our puzzle game is the animated 3D image selector. In this recipe,
we show you how to render the animated carousel-like selector and interact with the user.
Getting ready
Before proceeding with this recipe, you may need to go back to
Chapter 7
,
Cross-platform
UI and Input System
, and read how the
Canvas
class works. A bit of mathematics will be
required to understand better how the code in this recipe works.