Time for action – creating a skybox
To create a skybox for Mars Runner, perform the following steps:
1. Add a new class file called
Skybox.cs
to theMars Runner
project.2. Add the following
using
declaration at the beginning of theSkybox
class file:using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics;
3. Add fields to the
Skybox
class as follows:#region Fields private GraphicsDevice device; private Texture2D texture; private VertexBuffer cubeVertexBuffer; private List<VertexPositionTexture> vertices = new List<VertexPositionTexture>(); private float rotation = 0f; #endregion
4. Create a constructor for the
Skybox
class as follows:#region Constructor public Skybox( GraphicsDevice graphicsDevice, Texture2D texture) { device = graphicsDevice; this.texture = texture; // Create the cube's vertical faces BuildFace( new Vector3(0, 0, 0), new Vector3(0, 1, 1), new Vector2(0, 0.25f)); // west face BuildFace( ...