HaxeFlixel/flixel — pull request #895 by Gama11 (2014-02-23 15:17:27+00:00)
Title: Abstract default cameras into FlxCamera.defaultCameras for customizability

Consider the following scenario:

You have a pixel art game with a resolution of 320x240 but a window size that is twice that, so the camera zoom level is 2. This can be problematic in conjunction with using text - with pixel fonts like the flixel default one, you're even more limited in the range of possible sizes than normally because of the scaling that's going on (those fonts only look good at powers of two, 8px, 16px etc...). With a regular font that uses anti-aliasing, it immediately looks shitty when you scale it up ([screenshot from the person who ran into this issue / inspired this PR](http://i.snag.gy/KzoxP.jpg)).

The obvious / clever solution to this is using a seperate FlxCamera with a zoom level of one that only displays the text. With this you run into an issue though: the default cameras are hardcoded to `FlxG.cameras.list`. This means that if you were to create a `textCamera`, *all* objects would be rendered on that by default, which means you'd have to change the `cameras` array of every single sprite to only use `FlxG.camera` except for the texts, which use `textCamera`.

With the changes in this pull request, it's as simple as in the following code snippet:

```haxe
package;

import flixel.FlxCamera;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.text.FlxText;
import flixel.util.FlxColor;
import flixel.system.FlxAssets;

class PlayState extends FlxState
{
var textCamera:FlxCamera;

override public function create():Void
{
FlxG.cameras.add(textCamera = new FlxCamera(0, 0, 640, 480, 1));
textCamera.bgColor = FlxColor.TRANSPARENT;

var sprite = new FlxSprite().loadGraphic(GraphicLogo);
add(sprite);

FlxCamera.defaultCameras = [FlxG.camera];

var text = new FlxText(0, 0, 200, "Hello World");
text.cameras = [textCamera];
add(text);

super.create();
}

override public function update():Void
{
super.update();
}
}
```

This is with a `FlxGame` set up like this:

```haxe
new FlxGame(320, 240, PlayState, 2)
```