Game Development Reference
In-Depth Information
right to left. Altering the scrolling direction can cause the background to scroll in
any direction desired. This would be useful in a space exploration game where the
background could move in the opposite direction to the player's movement.
The scrolling class also has a Speed member; this isn't strictly necessary as the
speed of the scrolling could be encoded as the magnitude of the vector, but
separating the speed makes it simpler to alter. The direction and speed are used
to move the U,V data of the vertices in the Update method.
This background can now be added into the Level class.
ScrollingBackground _background;
ScrollingBackground _backgroundLayer;
public Level(Input input, TextureManager textureManager, PersistantGa-
meData gameData)
{
_input ¼ input;
_gameData ¼ gameData;
_textureManager ¼ textureManager;
_background ¼ new ScrollingBackground(textureManager.Get
("background"));
_background.SetScale(2, 2);
_background.Speed ¼ 0.15f;
_backgroundLayer ¼ new ScrollingBackground(textureManager.Get
("background_layer_1"));
_backgroundLayer.Speed ¼ 0.1f;
_backgroundLayer.SetScale(2.0, 2.0);
These two background objects are created in the constructor and each is scaled
by two. The backgrounds are scaled up because the texture is about half the size
of the screen area. The texture is scaled to make the texture large enough to
entirely cover the playing area without leaving gaps at the edges.
The two backgrounds scroll at different speeds. This produces what is known as a
parallax effect. The human brain understands the 3D world through a number of
different cues known as depth cues. For instance, each eye sees a slightly different
angle of the world, and the differences between these views can be used to
determine the third dimension. This is known as the binocular cue.
 
Search WWH ::




Custom Search