June 2015
Intermediate to advanced
388 pages
7h 31m
English
We will get a bit more mobile than a static border. Here, we will add an update method to a simple Star class, which can be used to randomly switch the star on and off.
We set the type as normal and create a random location for the star within the confines of the border and call setWorldLocation() as always.
Stars will be drawn as points, so our vertex array will simply contain one vertex at model space 0,0,0. Then, we call setVertices() as usual.
Create a new class, call it Star, and enter the discussed code:
public class Star extends GameObject{ // Declare a random object here because // we will use it in the update() method // and we don't want GC to have to keep clearing it up Random r; public Star(int mapWidth, int mapHeight){ ...Read now
Unlock full access