Game Development Reference
In-Depth Information
public static Pixmap mainMenu ;
public static Pixmap buttons ;
public static Pixmap help1 ;
public static Pixmap help2 ;
public static Pixmap help3 ;
public static Pixmap numbers ;
public static Pixmap ready ;
public static Pixmap pause ;
public static Pixmap gameOver ;
public static Pixmap headUp ;
public static Pixmap headLeft ;
public static Pixmap headDown ;
public static Pixmap headRight ;
public static Pixmap tail ;
public static Pixmap stain1 ;
public static Pixmap stain2 ;
public static Pixmap stain3 ;
public static Sound click ;
public static Sound eat ;
public static Sound bitten ;
}
We have a static member for every image and sound we load from the assets. If we want to use
one of these assets, we can do something like this:
game.getGraphics().drawPixmap(Assets.background, 0, 0)
or something like this:
Assets.click.play(1);
Now that's convenient. However, note that nothing is keeping us from overwriting those static
members, as they are not final. But as long as we don't overwrite them, we are safe. These
public, non-final members actually make this “design pattern� an anti-pattern. For our game, it's
OK to be a little lazy, though. A cleaner solution would hide the assets behind setters and getters
in a so-called singleton class . We'll stick to our poor-man's asset manager.
Settings: Keeping Track of User Choices and High Scores
There are two other things that we need to load in the loading screen: the user settings and the
high scores. If you look back at the main menu and high-scores screens in Chapter 3, you'll see
that we allow the user to toggle the sounds and that we store the top five high scores. We'll save
these settings to the external storage so that we can reload them the next time the game starts.
For this, we'll implement another simple class, called Settings , as shown in Listing 6-3. The
listing is split up, with comments interpersed.
 
Search WWH ::




Custom Search