STAR / MAIN
Making a Star Class
First we'll need to create a Star class.
Drawing the Stars
In the Main Tab, we'll need to actually create the stars. Look at how we make an ArrayList of objects, and mimic that syntax. Here's a checklist of places we'll need to add code:
At the top of the program
Declare an ArrayList of Stars
Initialize the ArrayList of Stars
Write a loop that executes 500 times.
Inside this loop, add a new star to the list of stars.
Loop through all the stars
Inside this loop, call render() on each star
STAR / MAIN
The Update Method
Add a method called update() to the Star class.
Back in main, we'll need to write code to call this method. Go to the act() method in the main tab. Write a loop that calls your update() method on each Star.
Notice that we didn't just set y to zero. Consider what would happen if our stars moved faster than one per frame.
For example, if stars moved by 5 pixels per frame, all stars between height and height - 5 would all be moved into a single "band" at zero.
By subtracting height instead, we avoid this problem.
DEPTH OF FIELD EFFECT
Different Sizes and Motion
Not all stars are the same distance away. Let's represent that by their size and motion.
A "nearby" star will have a larger size
A "nearby" star will move faster relative to our viewpoint
To do so, first we'll need to set size to a random value in the constructor:
Next, instead of increase y by 1 every frame, we'll increase it by a value related to size.
Finally, we may want to make a nearby star appear bright and a far away star appear dim. Let's change one more line of code in render():
Make sure your stars are moving but subtle. If they are too big, too bright, or too fast you run two risks:
The player may think they're bullets
It's distracting / a strain on the eyes