Camera - Rombusevil/flixel-gdx GitHub Wiki
In this guide you’ll learn how to use the camera system in flixel. The camera is used to display the game’s visuals. By default one camera is setup, that’s the same size as the game window. You can add more cameras to support split screen for example. The default camera can be access via FlxG.camera
and FlxG.cameras
for all cameras that are used.
The boundaries are the space which the camera is allowed to move and it can be set via setBounds()
.
FlxG.camera.setBounds(0, 0, 1024, 640, true);
If your game is 320 x 640, it means the camera can scroll horizontal.
The camera comes with 4 follow style presets.
STYLE_LOCKON (default) |
Camera has no deadzone. Just tracks the focus object directly. |
STYLE_PLATFORMER |
Camera deadzone is noarrow, but tall. |
STYLE_TOPDOWN |
Camera deadzone is a medium-size square around the focus object. |
STYLE_TOPDOWN_TIGHT |
Camera deadzone is a small square around the focus object. |
To follow an object with the camera you must call follow()
.
FlxG.camera.follow(player, FlxCamera.STYLE_PLATFORMER);
Examples:
The FlxCamera class comes with three special effects. You can pass parameters like the duration and callback which will be fired when the effect is ended.
fade() |
The screen is gradually filled with this color. |
flash() |
The screen is filled with this color and gradually returns to normal. |
shake() |
A simple screen-shake effect. |
This snippet shows how to use fade effect.
FlxG.fade(0xFF000000, 2, new IFlxCamera()
{
@Override
public void callback()
{
FlxG.log("Fade ended");
}
});
Examples: