A sprite-based star field

Let's put our new Sprite class to use by creating a scrolling star field. On the SpriteSheet.png file we added to the project earlier, there is a 50 by 50 pixel empty white square located at 0,450 in the image. As we saw in the introductory SquareChase game, we can use an empty white sprite in combination with the TintColor parameter of the SpriteBatch.Draw() method to draw squares of any color we wish. We will make use of this ability to create slight color variations in the stars in the star field to make them look more realistic than if they were simply uniformly colored squares.

In order to create the star field, we will create 200 sprites and place them on the screen randomly. They will have a velocity that will slowly draw them down the screen. The StarField class will be responsible for monitoring the stars and determining when they fall off the bottom of the screen. When this happens, they will be placed back at the top of the screen at a random location.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.40.177