FlixelCamera
View sourceclass
org.flixelgdx.FlixelCamera
A powerful camera class that controls world-to-screen projection, parallax scrolling, zoom, and screen effects such as flash, fade, and shake.
In a full FlixelGDX game, cameras are usually managed by FlixelGame. You can also use FlixelCamera in a plain libGDX ApplicationListener. When Flixel.game is null, window size and follow frame rate fall back to Gdx.graphics (call FlixelCamera.update(...) from resize as usual).
Every camera wraps a libGDX Camera and Viewport internally. By default, an OrthographicCamera and FitViewport are used. The viewport type is controlled by the static FlixelCamera.viewportFactory; platform launchers override it to supply a different viewport (for example, the Android launcher installs an ExtendViewport so the game fills the screen without letterboxing). Custom types can also be provided directly via the constructor overloads.
FitViewport scales the game world to the window, so the world-to-screen factor is often not a whole number when the window is larger than the camera's internal size (e.g. fullscreen). libGDX BitmapFont defaults to integer-snapped glyph quads, which looks blocky under that scaling. Set BitmapFont.setUseIntegerPositions(...) to false on fonts you draw through this pipeline (FlixelGDX does this for FlixelText and registry fonts automatically).
Constructors
FlixelCamera()
Creates a camera sized to the current window using the default OrthographicCamera and FlixelCamera.viewportFactory.
FlixelCamera(int, int)
Creates a camera with the given dimensions using the default camera and viewport types.
Parameters:
| Name | Description |
|---|---|
width | The width of the camera display in game pixels. |
height | The height of the camera display in game pixels. |
FlixelCamera(int, int, Camera)
Creates a camera with a custom libGDX Camera, wrapped in the default viewport from FlixelCamera.viewportFactory.
Parameters:
| Name | Description |
|---|---|
width | The width of the camera display in game pixels. |
height | The height of the camera display in game pixels. |
camera | A custom libGDX Camera (e.g. PerspectiveCamera). |
FlixelCamera(int, int, Viewport)
Creates a camera with a custom libGDX Viewport. The camera is extracted from the viewport.
Parameters:
| Name | Description |
|---|---|
width | The width of the camera display in game pixels. |
height | The height of the camera display in game pixels. |
viewport | A custom libGDX Viewport (e.g. ScreenViewport). |
FlixelCamera(float, float, int, int, float)
Creates a camera at the given display position, size, and zoom level using default types.
Parameters:
| Name | Description |
|---|---|
x | X location of the camera's display in native screen pixels. |
y | Y location of the camera's display in native screen pixels. |
width | The width of the camera display in game pixels. 0 = window width. |
height | The height of the camera display in game pixels. 0 = window height. |
zoom | The initial zoom level. 0 = FlixelCamera.defaultZoom. |
FlixelCamera(float, float, int, int, float, Camera, Viewport)
Full constructor allowing fully custom libGDX Camera and Viewport types.
If viewport is provided, its camera is used (the camera parameter is ignored). If only camera is provided, it is wrapped in a default viewport. If neither is provided, an OrthographicCamera and a default viewport are created.
When viewport is null, the viewport is created by FlixelCamera.viewportFactory. Platform launchers set this factory before any camera is built, so the right viewport type is used automatically (for example, FitViewport on desktop and ExtendViewport on Android).
Parameters:
| Name | Description |
|---|---|
x | X location of the camera's display in native screen pixels. |
y | Y location of the camera's display in native screen pixels. |
width | The width of the camera display in game pixels. 0 = window width. |
height | The height of the camera display in game pixels. 0 = window height. |
zoom | The initial zoom level. 0 = FlixelCamera.defaultZoom. 2 = 2x magnification. |
camera | Custom libGDX Camera, or null for a default OrthographicCamera. |
viewport | Custom libGDX Viewport, or null to use FlixelCamera.viewportFactory. |
Fields
defaultZoom
Any FlixelCamera with a zoom of <= 0 (the default constructor value) will receive this zoom level instead.
viewportFactory
Factory used to create the default Viewport whenever a new FlixelCamera is constructed without an explicit viewport.
The built-in default creates a FitViewport, which letterboxes the game world to fit the window. Platform launchers replace this before any camera is built - for example, the Android launcher assigns an ExtendViewport so the game fills the device screen without black bars.
To use a custom viewport for every camera created after the assignment:
FlixelCamera.viewportFactory = (w, h, cam) -> new ScreenViewport(cam);
Passing a custom Viewport to the constructor always takes priority over this field.
initialZoom
Zoom captured at construction time; useful for resetting to the original scale.
alpha
The alpha value of this camera's display, from 0.0 (invisible) to 1.0 (fully opaque).
angle
The rotation angle of the camera display in degrees.
followLeadX
Horizontal look-ahead offset applied to the follow target's world position. Positive values shift the visible region ahead of the target along the X axis.
followLeadY
Vertical look-ahead offset applied to the follow target's world position. Positive values shift the visible region ahead of the target along the Y axis.
followLerp
The ratio of the distance to the follow target the camera moves per 1/60 sec. 1.0 snaps to the target each frame. 0.0 stops all movement. Lower values produce smoother, lagging motion.
maxScrollX
Upper bound of the camera's scroll on the X axis. Float.NaN means unbounded.
See Also: .setScrollBounds
maxScrollY
Upper bound of the camera's scroll on the Y axis. Float.NaN means unbounded.
See Also: .setScrollBounds
minScrollX
Lower bound of the camera's scroll on the X axis. Float.NaN means unbounded.
See Also: .setScrollBounds
minScrollY
Lower bound of the camera's scroll on the Y axis. Float.NaN means unbounded.
See Also: .setScrollBounds
scrollX
The camera's X scroll position in world coordinates. This is the left edge of the visible world region. Use FlixelCamera.focusOn(float, float) to center on a specific world point.
scrollY
The camera's Y scroll position in world coordinates. This is the top edge of the visible world region. Use FlixelCamera.focusOn(float, float) to center on a specific world point.
targetOffsetX
Horizontal offset applied to the follow target's world position before follow math runs. Use this to track a point offset from the target's center (e.g. track ahead of a character).
targetOffsetY
Vertical offset applied to the follow target's world position before follow math runs. Use this to track a point offset from the target's center.
x
The X position of this camera's display in native screen pixels.
Note that FlixelCamera.getZoom() does NOT affect this value.
y
The Y position of this camera's display in native screen pixels.
Note thatFlixelCamera.getZoom() does NOT affect this value.
width
How wide the camera display is, in game pixels.
height
How tall the camera display is, in game pixels.
bgColor
The natural background color of the camera. Defaults to black.
color
The color tint of the camera display.
deadzone
The dead zone rectangle, measured from the camera's bottom-left corner in game pixels.
The camera always keeps the follow target inside this zone, unless bumping against scroll bounds. For rapid prototyping, use the preset styles via FlixelCamera.follow(...).
style
The current follow style used when a FlixelCamera.target is set.
target
The FlixelPositional this camera follows.
You can set this value via FlixelCamera.follow(FlixelPositional).
centerCameraOnResize
Whether the libGDX viewport should re-center the camera when the game window is resized.
Split-screen setups often want this enabled (default) to match existing behavior. Disable it to preserve the scroll position through resizes.
pixelPerfectRender
Whether positions of rendered objects are rounded to whole pixels.
pixelPerfectShake
If true, screen shake offsets are rounded to whole pixels. Falls back to FlixelCamera.pixelPerfectRender when false.
useBgAlphaBlending
Whether to use alpha blending for the camera's background fill.
useSubScreenViewport
When true, FlixelCamera.update(...) fits this camera into the screen rectangle (x, y, width, height) instead of the full window. When false, placement is inferred when Flixel.game has multiple cameras (horizontal/vertical strips, picture-in-picture, etc.).
Methods
apply()
Applies the viewport's OpenGL scissor rectangle.
Call before rendering through this camera.
update(int, int, boolean)
Updates the viewport in response to a window resize event.
Parameters:
| Name | Description |
|---|---|
screenWidth | The new screen width in pixels. |
screenHeight | The new screen height in pixels. |
centerCamera | Whether to re-center the camera in the viewport. |
update(float)
Updates the camera scroll, follow logic, and active effects. Called once per frame.
Parameters:
| Name | Description |
|---|---|
elapsed | Seconds that have elapsed since the last frame. |
applyLibCameraTransform()
Pushes FlixelCamera.scrollX/FlixelCamera.scrollY, zoom, angle, and shake offsets into the underlying libGDX Camera.
Call this after mutating scroll outside FlixelCamera.update(float) (e.g., during a debug pause pan) and before Viewport.unproject(...) or any rendering. Safe to call every frame; FlixelCamera.update(float) ends with this automatically.
Drawables use view (batch) coordinates from FlixelCamera.worldToViewX(float, float) and FlixelCamera.worldToViewY(float, float) (see FlixelSprite.draw(FlixelBatch)). The camera is positioned at the center of the full visible world so that view-space (0, 0) lands at the screen's top-left corner. For viewports that extend the world beyond the design dimensions (e.g. ExtendViewport on Android), the camera accounts for the extended area so world (0, 0) still maps to the screen edge and Flixel.getWidth() correctly reflects the full visible width.
follow(FlixelPositional)
Tells this camera to follow the given object using FollowStyle.LOCKON and a lerp of 1.0f (instant snap).
Parameters:
| Name | Description |
|---|---|
target | The object to follow. Pass null to stop following. |
follow(FlixelPositional, FollowStyle)
Tells this camera to follow the given object with the specified style and a lerp of 1.0f.
Parameters:
| Name | Description |
|---|---|
target | The object to follow. Pass null to stop following. |
style | One of the preset FollowStyle dead zone presets. |
follow(FlixelPositional, FollowStyle, float)
Tells this camera to follow the given object.
Parameters:
| Name | Description |
|---|---|
target | The object to follow. Pass null to stop following. |
style | One of the preset FollowStyle dead zone presets. |
lerp | How much lag the camera has. 1.0f = snap, lower = smoother. |
focusOn(float, float)
Instantly moves the camera so the given world point is centered.
Parameters:
| Name | Description |
|---|---|
worldX | World-space X to center on. |
worldY | World-space Y to center on. |
snapToTarget()
Snaps the camera to the current FlixelCamera.target position with no easing, then clamps scroll to bounds. Useful after teleporting the target.
setScrollBounds(float, float, float, float)
Specifies the scroll bounds for each axis. Pass Float.NaN for any side to leave it unbounded.
Parameters:
| Name | Description |
|---|---|
minX | Lower X bound, or Float.NaN. |
maxX | Upper X bound, or Float.NaN. |
minY | Lower Y bound, or Float.NaN. |
maxY | Upper Y bound, or Float.NaN. |
setScrollBoundsRect(float, float, float, float)
Specifies scroll bounds as a bounding rectangle (typically the level size).
Parameters:
| Name | Description |
|---|---|
x | Smallest X value (usually 0). |
y | Smallest Y value (usually 0). |
w | Largest X extent (usually level width). |
h | Largest Y extent (usually level height). |
setScrollBoundsRect(float, float, float, float, boolean)
Specifies scroll bounds as a bounding rectangle.
Parameters:
| Name | Description |
|---|---|
x | Smallest X value (usually 0). |
y | Smallest Y value (usually 0). |
w | Largest X extent (usually level width). |
h | Largest Y extent (usually level height). |
updateWorld | Reserved for future use (quad-tree bounds). |
updateScroll()
Clamps FlixelCamera.scrollX and FlixelCamera.scrollY to the configured scroll bounds. Called automatically each frame by FlixelCamera.update(float).
flash()
Flashes white for 1 second.
flash(Color)
Flashes the given color for 1 second.
Parameters:
| Name | Description |
|---|---|
color | The color to flash. |
flash(Color, float)
Flashes the given color for the specified duration.
Parameters:
| Name | Description |
|---|---|
color | The color to flash. |
duration | How long the flash takes to fade out, in seconds. |
flash(Color, float, Runnable, boolean)
Fills the screen with the given color and gradually fades it back to normal.
Parameters:
| Name | Description |
|---|---|
color | The color to flash. |
duration | How long the flash takes to fade out, in seconds. |
onComplete | Callback invoked when the flash finishes, or null. |
force | If true, resets any currently running flash. |
flash(FlixelColor)
Flashes the given color for 1 second.
Parameters:
| Name | Description |
|---|---|
color | The color to flash. |
flash(FlixelColor, float)
Flashes the given color for the specified duration.
Parameters:
| Name | Description |
|---|---|
color | The color to flash. |
duration | How long the flash takes to fade out, in seconds. |
flash(FlixelColor, float, Runnable, boolean)
Fills the screen with the given color and gradually fades it back to normal.
Parameters:
| Name | Description |
|---|---|
color | The color to flash. |
duration | How long the flash takes to fade out, in seconds. |
onComplete | Callback invoked when the flash finishes, or null. |
force | If true, resets any currently running flash. |
fade()
Fades to black over 1 second.
fade(Color)
Fades to the given color over 1 second.
Parameters:
| Name | Description |
|---|---|
color | The color to fade to. |
fade(Color, float)
Fades to the given color over the specified duration.
Parameters:
| Name | Description |
|---|---|
color | The color to fade to. |
duration | How long the fade takes, in seconds. |
fade(Color, float, boolean)
Fades to or from the given color.
Parameters:
| Name | Description |
|---|---|
color | The color to fade to or from. |
duration | How long the fade takes, in seconds. |
fadeIn | true = fade FROM the color to clear. false = fade TO the color. |
fade(Color, float, boolean, Runnable, boolean)
Gradually fills the screen with or clears it of the given color.
Parameters:
| Name | Description |
|---|---|
color | The color to fade to or from. |
duration | How long the fade takes, in seconds. |
fadeIn | true = fade FROM the color to clear. false = fade TO the color. |
onComplete | Callback invoked when the fade finishes, or null. |
force | If true, resets any currently running fade. |
fade(FlixelColor)
Fades to the given color over 1 second.
Parameters:
| Name | Description |
|---|---|
color | The color to fade to. |
fade(FlixelColor, float)
Fades to the given color over the specified duration.
Parameters:
| Name | Description |
|---|---|
color | The color to fade to. |
duration | How long the fade takes, in seconds. |
fade(FlixelColor, float, boolean)
Fades to or from the given color.
Parameters:
| Name | Description |
|---|---|
color | The color to fade to or from. |
duration | How long the fade takes, in seconds. |
fadeIn | true = fade FROM the color to clear. false = fade TO the color. |
fade(FlixelColor, float, boolean, Runnable, boolean)
Gradually fills the screen with or clears it of the given color.
Parameters:
| Name | Description |
|---|---|
color | The color to fade to or from. |
duration | How long the fade takes, in seconds. |
fadeIn | true = fade FROM the color to clear. false = fade TO the color. |
onComplete | Callback invoked when the fade finishes, or null. |
force | If true, resets any currently running fade. |
shake()
Shakes with default intensity (0.05) for 0.5 seconds on both axes.
shake(float)
Shakes with the given intensity for 0.5 seconds on both axes.
Parameters:
| Name | Description |
|---|---|
intensity | The intensity of the shake. Typically a very small number like 0.05f. |
shake(float, float)
Shakes with the given intensity and duration on both axes.
Parameters:
| Name | Description |
|---|---|
intensity | The intensity of the shake. Typically a very small number like 0.05f. |
duration | How long the shake lasts, in seconds. |
shake(float, float, Runnable, boolean, FlixelAxes)
Applies a screen-shake effect.
Parameters:
| Name | Description |
|---|---|
intensity | Fraction of the camera size used as the max shake offset distance. Typically a very small number like 0.05f or 0.01f. |
duration | How long the shake lasts, in seconds. |
onComplete | Callback invoked when the shake finishes, or null. |
force | If true, resets any currently running shake (default behavior unlike flash/fade). |
axes | Which axes to shake on. |
stopFX()
Stops all screen effects (flash, fade, and shake) on this camera.
stopFlash()
Stops the flash effect on this camera.
stopFade()
Stops the fade effect on this camera.
stopShake()
Stops the shake effect on this camera.
fill(Color, boolean, float, Batch, Texture)
Fills the camera display with the specified color using the given batch and a 1x1 white Texture.
Parameters:
| Name | Description |
|---|---|
fillColor | The color to fill with (alpha channel is respected). |
blendAlpha | Whether to blend the alpha or overwrite previous contents. |
fxAlpha | Additional alpha multiplier, from 0.0 to 1.0. |
batch | An active Batch (must be between begin() and end()). |
whitePixel | A 1x1 white Texture used for color drawing. |
drawFX(Batch, Texture)
Draws active screen effects (flash and fade overlays) using the given batch. Call this after drawing all game objects but before batch.end().
Parameters:
| Name | Description |
|---|---|
batch | An active Batch (must be between begin/end). |
whitePixel | A 1x1 white Texture used for color drawing. |
containsPoint(float, float)
Checks whether this camera's display area contains the given point in screen coordinates.
Parameters:
| Name | Description |
|---|---|
px | Screen-space X to test. |
py | Screen-space Y to test. |
Returns: true if the point is inside the camera display.
containsPoint(float, float, float, float)
Checks whether this camera's display area overlaps a rectangle at the given screen position.
Parameters:
| Name | Description |
|---|---|
px | Bottom-left X of the rectangle in screen coordinates. |
py | Bottom-left Y of the rectangle in screen coordinates. |
w | Width of the rectangle. |
h | Height of the rectangle. |
Returns: true if any part of the rectangle overlaps the camera display.
containsRect(Rectangle)
Checks whether this camera's display area overlaps the given rectangle in screen coordinates.
Parameters:
| Name | Description |
|---|---|
rect | The rectangle to test. |
Returns: true if the rectangle overlaps the camera display.
worldToViewX(float, float)
Converts a world X coordinate into this camera's view (batch) X coordinate. Parallax uses the object's scroll factor on FlixelCamera.scrollX only; zoom is handled by FlixelCamera.getViewMarginX().
Parameters:
| Name | Description |
|---|---|
worldX | World-space X. |
scrollFactor | Parallax factor (1 = moves fully with the camera). |
Returns: View-space X (the same space used by FlixelSprite.draw(FlixelBatch) before libGDX projection).
worldToViewY(float, float)
Converts a world Y coordinate into this camera's view (batch) Y coordinate.
Parameters:
| Name | Description |
|---|---|
worldY | World-space Y. |
scrollFactor | Parallax factor (1 = moves fully with the camera). |
Returns: View-space Y.
See Also: .worldToViewX
setZoom(float)
Sets the zoom level. 1 = 1:1, 2 = 2x magnification (world appears larger). Cameras always zoom toward their center. FlixelCamera.getViewWidth() and margins update with zoom; FlixelCamera.worldToViewX(float, float) and FlixelCamera.worldToViewY(float, float) keep parallax and foreground objects aligned. Scroll is not auto-adjusted here (same idea as HaxeFlixel's set_zoom).
Parameters:
| Name | Description |
|---|---|
zoom | The new zoom level. Non-positive values fall back to FlixelCamera.defaultZoom. |
changeZoom(float)
Changes the zoom level by the given delta.
Parameters:
| Name | Description |
|---|---|
amount | The amount to add to the current zoom level. |
restoreScrollAndZoom(float, float, float)
Restores scroll and zoom together without re-running follow or deadzone setup. Used when leaving debug pause so inspect-tool mutations can be reverted exactly as they were before.
Parameters:
| Name | Description |
|---|---|
scrollX | World scroll X to restore. |
scrollY | World scroll Y to restore. |
zoomLevel | Zoom to restore. Non-positive values fall back to FlixelCamera.defaultZoom. |
setScale(float, float)
Sets the zoom-based scale of this camera. Because cameras use a single uniform zoom value, this assigns zoom to the average of scaleX and scaleY.
Parameters:
| Name | Description |
|---|---|
scaleX | The desired horizontal scale. |
scaleY | The desired vertical scale. |
copyFrom(FlixelCamera)
Copies the bounds, follow target, deadzone info, and scroll from another camera.
Parameters:
| Name | Description |
|---|---|
other | The camera to copy from. |
Returns: This camera for chaining.
onResize()
Called by the game's front-end on window resize. Repositions and resizes the internal viewport.
destroy()
Cleans up this camera's state, stopping all effects and clearing the follow target.
setShader(FlixelShader)
Assigns a post-processing shader to this camera. When set, the camera renders its scene into an internal FrameBuffer each frame and then composites the result to screen using the given shader.
The shader is NOT owned by the camera. Call FlixelShader.destroy() yourself when you are done with it. To remove the shader and return to direct rendering, pass null.
Changing the shader recreates the internal framebuffer. Passing the same shader object that is already set is safe but still recreates the framebuffer, so avoid calling this every frame.
Parameters:
| Name | Description |
|---|---|
shader | The shader to apply as a camera post-processing effect, or null to disable post-processing. |
getShader()
Returns the shader currently assigned to this camera, or null if none is set.
Returns: The active FlixelShader, or null.
getFbo()
Returns the internal FrameBuffer used for post-processing, or null if no shader has been assigned via FlixelCamera.setShader(FlixelShader).
Returns: The camera's framebuffer, or null.
getFboRegion()
Returns a Y-flipped TextureRegion wrapping the internal framebuffer's color texture. Used by FlixelGame to draw the captured scene through the camera's shader. Returns null if no shader has been assigned.
Returns: The framebuffer region, or null.
getCamera()
Returns the underlying libGDX Camera used for projection.
getViewport()
Returns the underlying libGDX Viewport used for screen scaling.
getWorldWidth()
Returns the world width as reported by the viewport. May differ from FlixelCamera.width after zoom or when a FitViewport adds letterbox bars.
getWorldHeight()
Returns the world height as reported by the viewport. May differ from FlixelCamera.height after zoom or when a FitViewport adds letterbox bars.
getViewWidth()
Returns the visible width of the camera's view in world units, accounting for the current zoom level (width / zoom).
getViewHeight()
Returns the visible height of the camera's view in world units, accounting for the current zoom level (height / zoom).
getViewX()
Returns the left edge of the visible world region in world coordinates. Equivalent to FlixelCamera.scrollX plus the zoom margin.
getViewY()
Returns the top edge of the visible world region in world coordinates. Equivalent to FlixelCamera.scrollY plus the zoom margin.
getViewLeft()
Returns the left world coordinate of the visible region. Alias for FlixelCamera.getViewX().
getViewTop()
Returns the top world coordinate of the visible region. Alias for FlixelCamera.getViewY().
getViewRight()
Returns the right world coordinate of the visible region.
getViewBottom()
Returns the bottom world coordinate of the visible region.
isInView(float, float, float, float)
Returns true if an axis-aligned rectangle in view space overlaps this camera's visible region.
The coordinates must already be in view space; that is, converted by FlixelCamera.worldToViewX(float, float) and FlixelCamera.worldToViewY(float, float) before being passed here. The check is a simple AABB overlap against the full visible range [0, viewportWidth/zoom] x [0, viewportHeight/zoom] and does not account for sprite rotation, making it a conservative test that errs on the side of drawing.
For viewports that extend the world beyond the design dimensions (e.g. ExtendViewport), the visible range will be larger than the camera's design width and height, so objects placed in that extended area are not incorrectly culled.
Parameters:
| Name | Description |
|---|---|
viewX | Left edge of the rectangle in view space. |
viewY | Bottom edge of the rectangle in view space. |
width | Width of the rectangle. |
height | Height of the rectangle. |
Returns: true if the rectangle is at least partially visible.
getViewMarginX()
Returns the horizontal margin between the camera buffer edge and the visible view area, in world units. This margin grows as zoom increases above 1.
getViewMarginY()
Returns the vertical margin between the camera buffer edge and the visible view area, in world units.
getViewMarginLeft()
Returns the left view margin in world units. Alias for FlixelCamera.getViewMarginX().
getViewMarginRight()
Returns the right view margin in world units. Alias for FlixelCamera.getViewMarginX().
getViewMarginTop()
Returns the top view margin in world units. Alias for FlixelCamera.getViewMarginY().
getViewMarginBottom()
Returns the bottom view margin in world units. Alias for FlixelCamera.getViewMarginY().
getViewMarginRect()
Returns a rectangle representing the view area within the camera buffer, using view-space coordinates. The returned Rectangle is an internal temporary instance shared by this camera - copy the result if you need to hold onto it past the current frame.
getZoom()
Returns the current zoom level. 1 = 1:1, 2 = 2x magnification.
getScaleX()
Returns the horizontal scale, which is equal to the zoom level.
getScaleY()
Returns the vertical scale, which is equal to the zoom level.
getTotalScaleX()
Returns the total horizontal scale. Equivalent to FlixelCamera.getScaleX().
getTotalScaleY()
Returns the total vertical scale. Equivalent to FlixelCamera.getScaleY().
setPosition(float, float)
Sets the screen-space display position of this camera.
Parameters:
| Name | Description |
|---|---|
x | X position in native screen pixels. |
y | Y position in native screen pixels. |
setSize(int, int)
Sets both FlixelCamera.width and FlixelCamera.height of the camera display.
Parameters:
| Name | Description |
|---|---|
width | The new width in game pixels. |
height | The new height in game pixels. |
setRegionMode(RegionMode)
Sets the screen-region mode for this camera. This changes how FlixelCamera.x/FlixelCamera.y and region sizes are interpreted when placing the viewport rectangle on screen. It does not affect world-space object movement, physics, or camera follow math.
Parameters:
| Name | Description |
|---|---|
regionMode | The new region mode. Must not be null. |
getRegionMode()
Returns the current RegionMode used for screen-space viewport placement.
setScreenRegion(float, float, int, int)
Sets the camera's screen rectangle in pixels. Interpretation depends on the current FlixelCamera.getRegionMode(): top-left anchored, bottom-left anchored, or center anchored.
Parameters:
| Name | Description |
|---|---|
x | Region X coordinate in pixels. |
y | Region Y coordinate in pixels. |
width | Region width in pixels. |
height | Region height in pixels. |
setScreenRegionNormalized(float, float, float, float)
Sets the camera's screen rectangle in normalized coordinates (0..1), relative to the window size. Only used when FlixelCamera.getRegionMode() is RegionMode.NORMALIZED_RECT. Normalized coordinates use a top-left origin (Y increases downward) for consistency with HaxeFlixel-style layout.
Parameters:
| Name | Description |
|---|---|
x | Normalized X position (0..1). |
y | Normalized Y position (0..1). |
width | Normalized width (0..1). |
height | Normalized height (0..1). |
clearScreenRegion()
Clears the custom pixel region set by FlixelCamera.setScreenRegion(...). After clearing, pixel-based modes fall back to the legacy fields (FlixelCamera.x, FlixelCamera.y, FlixelCamera.width, FlixelCamera.height).
isFlashActive()
Returns true if a flash effect is currently active on this camera.
getFlashActive()
Returns true if a flash effect is currently active on this camera.
isFadeActive()
Returns true if a fade effect is currently active on this camera.
getFadeActive()
Returns true if a fade effect is currently active on this camera.
isShakeActive()
Returns true if a shake effect is currently active on this camera.
getShakeActive()
Returns true if a shake effect is currently active on this camera.
getFlashColor()
Returns the current flash overlay color.
getFlashAlpha()
Returns the current flash overlay alpha, from 0.0 to 1.0.
getFadeColor()
Returns the current fade overlay color.
getFadeAlpha()
Returns the current fade overlay alpha, from 0.0 to 1.0.
getColor()
getGdxColor()
setColor(Color)
Copies RGBA from color into this tint.
setColor(FlixelColor)
Copies RGBA from color into this tint.
setBgColor(Color)
Sets the background color of this camera.
Parameters:
| Name | Description |
|---|---|
tint | The background color to set. Must not be null. |
setBgColor(FlixelColor)
Sets the background color of this camera.
Parameters:
| Name | Description |
|---|---|
tint | The background color to set. Must not be null. |
ViewportFactory
interface
org.flixelgdx.FlixelCamera.ViewportFactory
Factory that creates a libGDX Viewport for a new FlixelCamera.
Assign a custom implementation to FlixelCamera.viewportFactory to control the default viewport type for all subsequently created cameras. Platform launchers use this to install the appropriate viewport without touching game code. For one-off cameras, pass a Viewport directly to the constructor instead.
Methods
create(int, int, Camera)
Creates a new Viewport for a camera with the given design dimensions.
Parameters:
| Name | Description |
|---|---|
width | The camera's design width in game pixels. |
height | The camera's design height in game pixels. |
camera | The libGDX camera this viewport will wrap. |
Returns: A new Viewport instance. Must not be null.
FollowStyle
enum
org.flixelgdx.FlixelCamera.FollowStyle
Determines how a FlixelCamera follows a FlixelPositional.
Fields
LOCKON
Camera follows the target and keeps it centered on the screen with no dead zone. The camera snaps to the target's position each frame.
PLATFORMER
A horizontally-biased dead zone placed near the bottom of the camera. Useful for platformers to show more of what is ahead and to prevent the camera from moving up and down too frequently.
TOPDOWN
The dead zone is centered, allowing free camera movement in all directions. Commonly used in top-down games.
TOPDOWN_TIGHT
Like FlixelCamera.TOPDOWN but with a tighter (smaller) dead zone, so the camera follows the target more closely.
SCREEN_BY_SCREEN
The camera moves in whole-screen increments, jumping once the target leaves the current screen. Good for classic puzzle or arcade games with discrete screen segments.
NO_DEAD_ZONE
No dead zone. The camera only moves when explicitly scrolled; it does not track the target automatically.
Methods
values()
valueOf(String)
RegionMode
enum
org.flixelgdx.FlixelCamera.RegionMode
Defines how a FlixelCamera's screen region coordinates are interpreted when placing its viewport on the window.
These modes affect only screen-space camera placement and clipping. They do not change world coordinates, object movement, physics directions, or camera follow logic.
Fields
PIXEL_TOP_LEFT
Pixel coordinates with a top-left origin (X right, Y down) for the camera region.
Before calling libGDX Viewport.setScreenBounds(...), FlixelGDX converts this top-left region to libGDX's bottom-left screen bounds. This is also the default region mode.
Recommended for users familiar with HaxeFlixel-style screen layout semantics.
PIXEL_BOTTOM_LEFT
Pixel coordinates with a bottom-left origin (X right, Y up) for the camera region.
This is already in libGDX/OpenGL viewport terms, so conversion to Viewport.setScreenBounds(...) is direct.
Recommended for users who prefer native libGDX viewport coordinate conventions.
PIXEL_CENTERED
Pixel coordinates where x/y represent the region center.
FlixelGDX first resolves a top-left rectangle from the center anchor, then converts to libGDX bottom-left screen bounds for Viewport.setScreenBounds(...).
Recommended for stable split-screen or picture-in-picture placement across resize and maximize events.
NORMALIZED_RECT
Normalized region values (0..1) relative to current window size, using a top-left origin.
The normalized rectangle is converted to pixel top-left coordinates, then converted again to libGDX bottom-left bounds for Viewport.setScreenBounds(...).
Recommended for resolution-independent camera layouts that scale with window size.