Game Development Reference
In-Depth Information
This code is fairly straightforward. The first line creates a Tile object variable. Next,
we have two nested for loops that loop through every tile position in the game
world. Inside the inner for loop, we get the tile type for this position on the map and
look it up in the tile list. We store the result in the variable s so that we can use it
easily afterwards. The last line renders the tile. The first parameter here is the bit-
map containing the tiles. The second parameter is a rectangle specifying where we
want to draw the tile on the screen. The third parameter is the opacity. We have it set
to 1.0f so that the tile is completely opaque. The third parameter is the interpola-
tion mode. And the last parameter is another rectangle, which specifies what portion
of the tile sheet we want to draw on the screen. For this, we specify the part of the
tile sheet containing the tile we want to draw. For the x and y coordinates of both
rectangle parameters, you may have noticed that we are multiplying by 32. This is
because each tile is 32 x 32 pixels in size. So, we have to multiply by 32 to get the
position of the tile within the tile sheet correctly. The fact that our tiles are 32 x 32
pixels in size is also why both rectangles we created here specify the value 32 for
their width and height parameters.
Rendering the player character
Now that we have code to draw the world, we need to draw the player character! For
this, we will create a method called RenderPlayer() . It's pretty short compared to
the RenderWorld() method. The following is the code:
public void RenderPlayer()
{
// Render the player character.
m_RenderTarget.DrawBitmap(m_PlayerSprites,
new Rectangle((int)
(m_Player.PositionX * 32),
(int)
(m_Player.PositionY * 32),
32, 32),
1.0f,
InterpolationMode.Linear,new
Rectangle(m_Player.AnimFrame * 32,
0, 32,
Search WWH ::




Custom Search