Game Development Reference
In-Depth Information
Fig. 4.1 SpriteDrawing
project and its content
reference to Painter in the
solution explorer
value of 255, it is set to its maximum intensity. So, the expression new Color(835, 0, 0)
actually results in a color with RGB values of 255, 0, and 0. This means that for
about three quarters of a second, the displayed background color will be red, before
it turns black again.
4.3 Managing Game Assets
4.3.1 Introduction
In the previous sections, we have seen how to make a very basic game application by
writing our own class as a subclass of Game . We have seen how the graphics device
is initialized, and how we can use it to change the background color according to
the time passed. In this section, we will show how to draw images (or: sprites) on
the screen, which is the first step towards making a nice-looking game. Sprites are
generally loaded from a file. This means that any program that draws sprites is no
longer simply an isolated set of instructions, but it relies on game assets that are
stored somewhere. This immediately introduces a number of problems that we need
to take care of:
How do we tell the game engine where to find sprites?
How do we retrieve the information from an image file?
How do we draw a sprite on the screen?
In this section we are going to deal with these questions.
4.3.2 Locating Sprites
Before a program can use any kind of asset, it needs to know where these assets are
located. Look at the project SpriteDrawing in the solution explorer (see also Fig. 4.1 ).
You see that it contains a folder called 'Content References'. Inside this folder you
see that there is a shortcut to another project in this solution called 'Painter'. If you
open that project, you see that it contains some image files. This is how game assets
are dealt with. Game assets are stored in a separate Content project . Other projects
can then refer to that project in order to access these assets. This means that it is
also possible to use the same assets for different projects in the same solution. This
is very handy, because when a number of projects use the same assets, we do not
need to copy them for each project.
Search WWH ::




Custom Search