HaxeFlixel/flixel — pull request #1241 by LaughingLeader (2014-07-25 03:17:36+00:00)
Title: Added a global CachedGraphics persistence variable.

### Summary
If specified, `CachedGraphics` will use the `Persist:Null` value supplied by the
constructor. Otherwise, it defaults to the value of
`persistentCachedGraphics` in `FlxG.bitmap` (a.k.a. `BitmapFrontEnd`).

This allows globally setting what the persist value of `CachedGraphics`
should default to, making it easier to keep desired graphics persistent between state
changes.

#### Changes
1. Persist in `CachedGraphics`'s constructor becomes a `Null` variable, so that if `Persist` is null, `persist` in the `CachedGraphics` is set to the default value (the value of `FlxG.bitmap.persistentCachedGraphics`).
2. `BitmapFrontEnd` gets a simple `persistentCachedGraphics:Bool` so that persistence with all created `CachedGraphics` can be globally toggled.

#### Reasoning
1. Simply put, if one wishes to keep certain graphics persistent between state changes (`FlxSprite`, `FlxText` and so on), they have to manually adjust the `cachedGraphics.persist` variable for each object. This can be made easier with a global variable.

2. Rather than risk missing some objects, it's *considerably* easier to just set `FlxG.bitmap.persistentCachedGraphics = true`, create the objects that you wish to be persistent, and then `FlxG.bitmap.persistentCachedGraphics = false`.

3. Persistence is handy for objects that will be used in `Menu` and `Play` states of a game. My own project has a Leaderboard menu that generates quite a bit of names and entries. Only having to create these objects once is a *significant* advantage, since this menu is accessible from most areas of the game. Having an easy way to control the persistence of objects as a whole is extremely handy for this.