Creating Backgrounds For Your Game

September 20, 2025 Posted by zachary

So, it has been a while since my last update on my Beginning Game Programming challenge. But it is coming along again. This week, I completed Chapter 16, Creating Backgrounds for your games. In this chapter, we looked at creating a star field for your game. In the book this challenge is based on, the author created a class to add a field of stars to his games. Lucky for us, HaxeFlixel already had one. We had actually used it earlier in this challenge.

However, what we needed for Chapter 17 was a static field of stars, and the class that HaxeFlixel offered was an always moving field of stars. So we had to make some modifications. While doing this, I modified the original class and created a pull request to get my changes added.

With my changes, you can now set the star speed to 0 as well as change the direction the stars move when they do:

stars = new FlxStarField2D(); 
stars.setStarSpeed(0,0);
add(stars);
stars.setStarVelocityOffset(FlxPoint.get(-1, 0));

In our demo, we use our UFO class we created before to effect the direction the stars move. As you fly the UFO around the screen, the stars move in the opposite direction.

That is really it for this chapter. But it helped us learn some about modifying existing behavior of HaxeFlixel to suit our needs. And the changes we have made will be used in the next couple of games.

You can see the the full Kitchen Infestation game at itch.io. You can see the source code for the game on Codeberg.

Leave a Reply

Your email address will not be published. Required fields are marked *