Game Development Reference
In-Depth Information
Parallax is another one of these cues; simply put, objects further from the viewer
appear to move slower than those closer to the view. Think of driving in a car
with a large mountain in the distance. The mountain appears to move very
slowly, but trees next to the road fly past. This is a depth cue, and the brain
knows that the mountain is far away.
Parallax is easy to fake. A fast scrolling star field appears to have stars close to the
spaceship; another background moving more slowly appears to have stars far
away. The background classes merely need to move at different speeds, and this
gives the background a feeling of depth.
The background objects need to be rendered and updated. This requires more
code changes.
public void Update(double elapsedTime)
{
_background.Update((float)elapsedTime);
_backgroundLayer.Update((float)elapsedTime);
// A little later in the code
public void Render(Renderer renderer)
{
_background.Render(renderer);
_backgroundLayer.Render(renderer);
Run the code and check out the parallax effect. It's quite subtle with the given
star fields, so feel free to modify the images or add several more layers.
The ship now appears to be zooming along in space, and everything suddenly
feels a lot more game-like. The next task is to add an enemy.
Adding Some Simple Enemies
The enemies will be represented by a sprite and therefore they will use the
Sprite class. The enemy sprite should be different from the player sprite so add
a new sprite texture called spaceship2.tga from the CD Assets directory. Change
its properties so that it will be copied to the \bin directories when the program is
built.
This snippet of code loads the texture into the texture manager.
 
Search WWH ::




Custom Search