Skip to main content

FlixelCamera

View source

class

org.flixelgdx.FlixelCamera

public class FlixelCamera extends FlixelBasic implements FlixelColorable, FlixelShaderable

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()

public FlixelCamera()

Creates a camera sized to the current window using the default OrthographicCamera and FlixelCamera.viewportFactory.


FlixelCamera(int, int)

public FlixelCamera(int width, int height)

Creates a camera with the given dimensions using the default camera and viewport types.

Parameters:

NameDescription
widthThe width of the camera display in game pixels.
heightThe height of the camera display in game pixels.

FlixelCamera(int, int, Camera)

public FlixelCamera(int width, int height, Camera camera)

Creates a camera with a custom libGDX Camera, wrapped in the default viewport from FlixelCamera.viewportFactory.

Parameters:

NameDescription
widthThe width of the camera display in game pixels.
heightThe height of the camera display in game pixels.
cameraA custom libGDX Camera (e.g. PerspectiveCamera).

FlixelCamera(int, int, Viewport)

public FlixelCamera(int width, int height, Viewport viewport)

Creates a camera with a custom libGDX Viewport. The camera is extracted from the viewport.

Parameters:

NameDescription
widthThe width of the camera display in game pixels.
heightThe height of the camera display in game pixels.
viewportA custom libGDX Viewport (e.g. ScreenViewport).

FlixelCamera(float, float, int, int, float)

public FlixelCamera(float x, float y, int width, int height, float zoom)

Creates a camera at the given display position, size, and zoom level using default types.

Parameters:

NameDescription
xX location of the camera's display in native screen pixels.
yY location of the camera's display in native screen pixels.
widthThe width of the camera display in game pixels. 0 = window width.
heightThe height of the camera display in game pixels. 0 = window height.
zoomThe initial zoom level. 0 = FlixelCamera.defaultZoom.

FlixelCamera(float, float, int, int, float, Camera, Viewport)

public FlixelCamera(float x, float y, int width, int height, float zoom, Camera camera, Viewport 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:

NameDescription
xX location of the camera's display in native screen pixels.
yY location of the camera's display in native screen pixels.
widthThe width of the camera display in game pixels. 0 = window width.
heightThe height of the camera display in game pixels. 0 = window height.
zoomThe initial zoom level. 0 = FlixelCamera.defaultZoom. 2 = 2x magnification.
cameraCustom libGDX Camera, or null for a default OrthographicCamera.
viewportCustom libGDX Viewport, or null to use FlixelCamera.viewportFactory.

Fields

defaultZoom

public static float defaultZoom

Any FlixelCamera with a zoom of <= 0 (the default constructor value) will receive this zoom level instead.


viewportFactory

public static ViewportFactory 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

public final float initialZoom

Zoom captured at construction time; useful for resetting to the original scale.


alpha

public float alpha

The alpha value of this camera's display, from 0.0 (invisible) to 1.0 (fully opaque).


angle

public float angle

The rotation angle of the camera display in degrees.


followLeadX

public float 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

public float 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

public float 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

public float maxScrollX

Upper bound of the camera's scroll on the X axis. Float.NaN means unbounded.

See Also: .setScrollBounds


maxScrollY

public float maxScrollY

Upper bound of the camera's scroll on the Y axis. Float.NaN means unbounded.

See Also: .setScrollBounds


minScrollX

public float minScrollX

Lower bound of the camera's scroll on the X axis. Float.NaN means unbounded.

See Also: .setScrollBounds


minScrollY

public float minScrollY

Lower bound of the camera's scroll on the Y axis. Float.NaN means unbounded.

See Also: .setScrollBounds


scrollX

public float 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

public float 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

public float 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

public float 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

public float x

The X position of this camera's display in native screen pixels.

Note that FlixelCamera.getZoom() does NOT affect this value.


y

public float y

The Y position of this camera's display in native screen pixels.

Note thatFlixelCamera.getZoom() does NOT affect this value.


width

public int width

How wide the camera display is, in game pixels.


height

public int height

How tall the camera display is, in game pixels.


bgColor

public Color bgColor

The natural background color of the camera. Defaults to black.


color

public Color color

The color tint of the camera display.


deadzone

public Rectangle 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

public FollowStyle style

The current follow style used when a FlixelCamera.target is set.


target

public FlixelPositional target

The FlixelPositional this camera follows.

You can set this value via FlixelCamera.follow(FlixelPositional).


centerCameraOnResize

public boolean 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

public boolean pixelPerfectRender

Whether positions of rendered objects are rounded to whole pixels.


pixelPerfectShake

public boolean pixelPerfectShake

If true, screen shake offsets are rounded to whole pixels. Falls back to FlixelCamera.pixelPerfectRender when false.


useBgAlphaBlending

public boolean useBgAlphaBlending

Whether to use alpha blending for the camera's background fill.


useSubScreenViewport

public boolean 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()

public void apply()

Applies the viewport's OpenGL scissor rectangle.

Call before rendering through this camera.


update(int, int, boolean)

public void update(int screenWidth, int screenHeight, boolean centerCamera)

Updates the viewport in response to a window resize event.

Parameters:

NameDescription
screenWidthThe new screen width in pixels.
screenHeightThe new screen height in pixels.
centerCameraWhether to re-center the camera in the viewport.

update(float)

public void update(float elapsed)

Updates the camera scroll, follow logic, and active effects. Called once per frame.

Parameters:

NameDescription
elapsedSeconds that have elapsed since the last frame.

applyLibCameraTransform()

public void 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)

public void follow(FlixelPositional target)

Tells this camera to follow the given object using FollowStyle.LOCKON and a lerp of 1.0f (instant snap).

Parameters:

NameDescription
targetThe object to follow. Pass null to stop following.

follow(FlixelPositional, FollowStyle)

public void follow(FlixelPositional target, FollowStyle style)

Tells this camera to follow the given object with the specified style and a lerp of 1.0f.

Parameters:

NameDescription
targetThe object to follow. Pass null to stop following.
styleOne of the preset FollowStyle dead zone presets.

follow(FlixelPositional, FollowStyle, float)

public void follow(FlixelPositional target, FollowStyle style, float lerp)

Tells this camera to follow the given object.

Parameters:

NameDescription
targetThe object to follow. Pass null to stop following.
styleOne of the preset FollowStyle dead zone presets.
lerpHow much lag the camera has. 1.0f = snap, lower = smoother.

focusOn(float, float)

public void focusOn(float worldX, float worldY)

Instantly moves the camera so the given world point is centered.

Parameters:

NameDescription
worldXWorld-space X to center on.
worldYWorld-space Y to center on.

snapToTarget()

public void 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)

public void setScrollBounds(float minX, float maxX, float minY, float maxY)

Specifies the scroll bounds for each axis. Pass Float.NaN for any side to leave it unbounded.

Parameters:

NameDescription
minXLower X bound, or Float.NaN.
maxXUpper X bound, or Float.NaN.
minYLower Y bound, or Float.NaN.
maxYUpper Y bound, or Float.NaN.

setScrollBoundsRect(float, float, float, float)

public void setScrollBoundsRect(float x, float y, float w, float h)

Specifies scroll bounds as a bounding rectangle (typically the level size).

Parameters:

NameDescription
xSmallest X value (usually 0).
ySmallest Y value (usually 0).
wLargest X extent (usually level width).
hLargest Y extent (usually level height).

setScrollBoundsRect(float, float, float, float, boolean)

public void setScrollBoundsRect(float x, float y, float w, float h, boolean updateWorld)

Specifies scroll bounds as a bounding rectangle.

Parameters:

NameDescription
xSmallest X value (usually 0).
ySmallest Y value (usually 0).
wLargest X extent (usually level width).
hLargest Y extent (usually level height).
updateWorldReserved for future use (quad-tree bounds).

updateScroll()

public void updateScroll()

Clamps FlixelCamera.scrollX and FlixelCamera.scrollY to the configured scroll bounds. Called automatically each frame by FlixelCamera.update(float).


flash()

public void flash()

Flashes white for 1 second.


flash(Color)

public void flash(Color color)

Flashes the given color for 1 second.

Parameters:

NameDescription
colorThe color to flash.

flash(Color, float)

public void flash(Color color, float duration)

Flashes the given color for the specified duration.

Parameters:

NameDescription
colorThe color to flash.
durationHow long the flash takes to fade out, in seconds.

flash(Color, float, Runnable, boolean)

public void flash(Color color, float duration, Runnable onComplete, boolean force)

Fills the screen with the given color and gradually fades it back to normal.

Parameters:

NameDescription
colorThe color to flash.
durationHow long the flash takes to fade out, in seconds.
onCompleteCallback invoked when the flash finishes, or null.
forceIf true, resets any currently running flash.

flash(FlixelColor)

public void flash(FlixelColor color)

Flashes the given color for 1 second.

Parameters:

NameDescription
colorThe color to flash.

flash(FlixelColor, float)

public void flash(FlixelColor color, float duration)

Flashes the given color for the specified duration.

Parameters:

NameDescription
colorThe color to flash.
durationHow long the flash takes to fade out, in seconds.

flash(FlixelColor, float, Runnable, boolean)

public void flash(FlixelColor color, float duration, Runnable onComplete, boolean force)

Fills the screen with the given color and gradually fades it back to normal.

Parameters:

NameDescription
colorThe color to flash.
durationHow long the flash takes to fade out, in seconds.
onCompleteCallback invoked when the flash finishes, or null.
forceIf true, resets any currently running flash.

fade()

public void fade()

Fades to black over 1 second.


fade(Color)

public void fade(Color color)

Fades to the given color over 1 second.

Parameters:

NameDescription
colorThe color to fade to.

fade(Color, float)

public void fade(Color color, float duration)

Fades to the given color over the specified duration.

Parameters:

NameDescription
colorThe color to fade to.
durationHow long the fade takes, in seconds.

fade(Color, float, boolean)

public void fade(Color color, float duration, boolean fadeIn)

Fades to or from the given color.

Parameters:

NameDescription
colorThe color to fade to or from.
durationHow long the fade takes, in seconds.
fadeIntrue = fade FROM the color to clear. false = fade TO the color.

fade(Color, float, boolean, Runnable, boolean)

public void fade(Color color, float duration, boolean fadeIn, Runnable onComplete, boolean force)

Gradually fills the screen with or clears it of the given color.

Parameters:

NameDescription
colorThe color to fade to or from.
durationHow long the fade takes, in seconds.
fadeIntrue = fade FROM the color to clear. false = fade TO the color.
onCompleteCallback invoked when the fade finishes, or null.
forceIf true, resets any currently running fade.

fade(FlixelColor)

public void fade(FlixelColor color)

Fades to the given color over 1 second.

Parameters:

NameDescription
colorThe color to fade to.

fade(FlixelColor, float)

public void fade(FlixelColor color, float duration)

Fades to the given color over the specified duration.

Parameters:

NameDescription
colorThe color to fade to.
durationHow long the fade takes, in seconds.

fade(FlixelColor, float, boolean)

public void fade(FlixelColor color, float duration, boolean fadeIn)

Fades to or from the given color.

Parameters:

NameDescription
colorThe color to fade to or from.
durationHow long the fade takes, in seconds.
fadeIntrue = fade FROM the color to clear. false = fade TO the color.

fade(FlixelColor, float, boolean, Runnable, boolean)

public void fade(FlixelColor color, float duration, boolean fadeIn, Runnable onComplete, boolean force)

Gradually fills the screen with or clears it of the given color.

Parameters:

NameDescription
colorThe color to fade to or from.
durationHow long the fade takes, in seconds.
fadeIntrue = fade FROM the color to clear. false = fade TO the color.
onCompleteCallback invoked when the fade finishes, or null.
forceIf true, resets any currently running fade.

shake()

public void shake()

Shakes with default intensity (0.05) for 0.5 seconds on both axes.


shake(float)

public void shake(float intensity)

Shakes with the given intensity for 0.5 seconds on both axes.

Parameters:

NameDescription
intensityThe intensity of the shake. Typically a very small number like 0.05f.

shake(float, float)

public void shake(float intensity, float duration)

Shakes with the given intensity and duration on both axes.

Parameters:

NameDescription
intensityThe intensity of the shake. Typically a very small number like 0.05f.
durationHow long the shake lasts, in seconds.

shake(float, float, Runnable, boolean, FlixelAxes)

public void shake(float intensity, float duration, Runnable onComplete, boolean force, FlixelAxes axes)

Applies a screen-shake effect.

Parameters:

NameDescription
intensityFraction of the camera size used as the max shake offset distance. Typically a very small number like 0.05f or 0.01f.
durationHow long the shake lasts, in seconds.
onCompleteCallback invoked when the shake finishes, or null.
forceIf true, resets any currently running shake (default behavior unlike flash/fade).
axesWhich axes to shake on.

stopFX()

public void stopFX()

Stops all screen effects (flash, fade, and shake) on this camera.


stopFlash()

public void stopFlash()

Stops the flash effect on this camera.


stopFade()

public void stopFade()

Stops the fade effect on this camera.


stopShake()

public void stopShake()

Stops the shake effect on this camera.


fill(Color, boolean, float, Batch, Texture)

public void fill(Color fillColor, boolean blendAlpha, float fxAlpha, Batch batch, Texture whitePixel)

Fills the camera display with the specified color using the given batch and a 1x1 white Texture.

Parameters:

NameDescription
fillColorThe color to fill with (alpha channel is respected).
blendAlphaWhether to blend the alpha or overwrite previous contents.
fxAlphaAdditional alpha multiplier, from 0.0 to 1.0.
batchAn active Batch (must be between begin() and end()).
whitePixelA 1x1 white Texture used for color drawing.

drawFX(Batch, Texture)

public void drawFX(Batch batch, Texture whitePixel)

Draws active screen effects (flash and fade overlays) using the given batch. Call this after drawing all game objects but before batch.end().

Parameters:

NameDescription
batchAn active Batch (must be between begin/end).
whitePixelA 1x1 white Texture used for color drawing.

containsPoint(float, float)

public boolean containsPoint(float px, float py)

Checks whether this camera's display area contains the given point in screen coordinates.

Parameters:

NameDescription
pxScreen-space X to test.
pyScreen-space Y to test.

Returns: true if the point is inside the camera display.


containsPoint(float, float, float, float)

public boolean containsPoint(float px, float py, float w, float h)

Checks whether this camera's display area overlaps a rectangle at the given screen position.

Parameters:

NameDescription
pxBottom-left X of the rectangle in screen coordinates.
pyBottom-left Y of the rectangle in screen coordinates.
wWidth of the rectangle.
hHeight of the rectangle.

Returns: true if any part of the rectangle overlaps the camera display.


containsRect(Rectangle)

public boolean containsRect(Rectangle rect)

Checks whether this camera's display area overlaps the given rectangle in screen coordinates.

Parameters:

NameDescription
rectThe rectangle to test.

Returns: true if the rectangle overlaps the camera display.


worldToViewX(float, float)

public float worldToViewX(float worldX, float scrollFactor)

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:

NameDescription
worldXWorld-space X.
scrollFactorParallax 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)

public float worldToViewY(float worldY, float scrollFactor)

Converts a world Y coordinate into this camera's view (batch) Y coordinate.

Parameters:

NameDescription
worldYWorld-space Y.
scrollFactorParallax factor (1 = moves fully with the camera).

Returns: View-space Y.

See Also: .worldToViewX


setZoom(float)

public void setZoom(float zoom)

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:

NameDescription
zoomThe new zoom level. Non-positive values fall back to FlixelCamera.defaultZoom.

changeZoom(float)

public void changeZoom(float amount)

Changes the zoom level by the given delta.

Parameters:

NameDescription
amountThe amount to add to the current zoom level.

restoreScrollAndZoom(float, float, float)

public void restoreScrollAndZoom(float scrollX, float scrollY, float zoomLevel)

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:

NameDescription
scrollXWorld scroll X to restore.
scrollYWorld scroll Y to restore.
zoomLevelZoom to restore. Non-positive values fall back to FlixelCamera.defaultZoom.

setScale(float, float)

public void setScale(float scaleX, float scaleY)

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:

NameDescription
scaleXThe desired horizontal scale.
scaleYThe desired vertical scale.

copyFrom(FlixelCamera)

public FlixelCamera copyFrom(FlixelCamera other)

Copies the bounds, follow target, deadzone info, and scroll from another camera.

Parameters:

NameDescription
otherThe camera to copy from.

Returns: This camera for chaining.


onResize()

public void onResize()

Called by the game's front-end on window resize. Repositions and resizes the internal viewport.


destroy()

public void destroy()

Cleans up this camera's state, stopping all effects and clearing the follow target.


setShader(FlixelShader)

public void setShader(FlixelShader shader)

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:

NameDescription
shaderThe shader to apply as a camera post-processing effect, or null to disable post-processing.

getShader()

public FlixelShader getShader()

Returns the shader currently assigned to this camera, or null if none is set.

Returns: The active FlixelShader, or null.


getFbo()

public FrameBuffer 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()

public TextureRegion 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()

public Camera getCamera()

Returns the underlying libGDX Camera used for projection.


getViewport()

public Viewport getViewport()

Returns the underlying libGDX Viewport used for screen scaling.


getWorldWidth()

public float 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()

public float 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()

public float getViewWidth()

Returns the visible width of the camera's view in world units, accounting for the current zoom level (width / zoom).


getViewHeight()

public float getViewHeight()

Returns the visible height of the camera's view in world units, accounting for the current zoom level (height / zoom).


getViewX()

public float getViewX()

Returns the left edge of the visible world region in world coordinates. Equivalent to FlixelCamera.scrollX plus the zoom margin.


getViewY()

public float getViewY()

Returns the top edge of the visible world region in world coordinates. Equivalent to FlixelCamera.scrollY plus the zoom margin.


getViewLeft()

public float getViewLeft()

Returns the left world coordinate of the visible region. Alias for FlixelCamera.getViewX().


getViewTop()

public float getViewTop()

Returns the top world coordinate of the visible region. Alias for FlixelCamera.getViewY().


getViewRight()

public float getViewRight()

Returns the right world coordinate of the visible region.


getViewBottom()

public float getViewBottom()

Returns the bottom world coordinate of the visible region.


isInView(float, float, float, float)

public boolean isInView(float viewX, float viewY, float width, float height)

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:

NameDescription
viewXLeft edge of the rectangle in view space.
viewYBottom edge of the rectangle in view space.
widthWidth of the rectangle.
heightHeight of the rectangle.

Returns: true if the rectangle is at least partially visible.


getViewMarginX()

public float 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()

public float getViewMarginY()

Returns the vertical margin between the camera buffer edge and the visible view area, in world units.


getViewMarginLeft()

public float getViewMarginLeft()

Returns the left view margin in world units. Alias for FlixelCamera.getViewMarginX().


getViewMarginRight()

public float getViewMarginRight()

Returns the right view margin in world units. Alias for FlixelCamera.getViewMarginX().


getViewMarginTop()

public float getViewMarginTop()

Returns the top view margin in world units. Alias for FlixelCamera.getViewMarginY().


getViewMarginBottom()

public float getViewMarginBottom()

Returns the bottom view margin in world units. Alias for FlixelCamera.getViewMarginY().


getViewMarginRect()

public Rectangle 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()

public float getZoom()

Returns the current zoom level. 1 = 1:1, 2 = 2x magnification.


getScaleX()

public float getScaleX()

Returns the horizontal scale, which is equal to the zoom level.


getScaleY()

public float getScaleY()

Returns the vertical scale, which is equal to the zoom level.


getTotalScaleX()

public float getTotalScaleX()

Returns the total horizontal scale. Equivalent to FlixelCamera.getScaleX().


getTotalScaleY()

public float getTotalScaleY()

Returns the total vertical scale. Equivalent to FlixelCamera.getScaleY().


setPosition(float, float)

public void setPosition(float x, float y)

Sets the screen-space display position of this camera.

Parameters:

NameDescription
xX position in native screen pixels.
yY position in native screen pixels.

setSize(int, int)

public void setSize(int width, int height)

Sets both FlixelCamera.width and FlixelCamera.height of the camera display.

Parameters:

NameDescription
widthThe new width in game pixels.
heightThe new height in game pixels.

setRegionMode(RegionMode)

public void setRegionMode(RegionMode 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:

NameDescription
regionModeThe new region mode. Must not be null.

getRegionMode()

public RegionMode getRegionMode()

Returns the current RegionMode used for screen-space viewport placement.


setScreenRegion(float, float, int, int)

public void setScreenRegion(float x, float y, int width, int height)

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:

NameDescription
xRegion X coordinate in pixels.
yRegion Y coordinate in pixels.
widthRegion width in pixels.
heightRegion height in pixels.

setScreenRegionNormalized(float, float, float, float)

public void setScreenRegionNormalized(float x, float y, float width, float height)

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:

NameDescription
xNormalized X position (0..1).
yNormalized Y position (0..1).
widthNormalized width (0..1).
heightNormalized height (0..1).

clearScreenRegion()

public void 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()

public boolean isFlashActive()

Returns true if a flash effect is currently active on this camera.


getFlashActive()

public boolean getFlashActive()

Returns true if a flash effect is currently active on this camera.


isFadeActive()

public boolean isFadeActive()

Returns true if a fade effect is currently active on this camera.


getFadeActive()

public boolean getFadeActive()

Returns true if a fade effect is currently active on this camera.


isShakeActive()

public boolean isShakeActive()

Returns true if a shake effect is currently active on this camera.


getShakeActive()

public boolean getShakeActive()

Returns true if a shake effect is currently active on this camera.


getFlashColor()

public Color getFlashColor()

Returns the current flash overlay color.


getFlashAlpha()

public float getFlashAlpha()

Returns the current flash overlay alpha, from 0.0 to 1.0.


getFadeColor()

public Color getFadeColor()

Returns the current fade overlay color.


getFadeAlpha()

public float getFadeAlpha()

Returns the current fade overlay alpha, from 0.0 to 1.0.


getColor()

public int getColor()

getGdxColor()

public Color getGdxColor()

setColor(Color)

public void setColor(Color tint)

Copies RGBA from color into this tint.


setColor(FlixelColor)

public void setColor(FlixelColor tint)

Copies RGBA from color into this tint.


setBgColor(Color)

public void setBgColor(Color tint)

Sets the background color of this camera.

Parameters:

NameDescription
tintThe background color to set. Must not be null.

setBgColor(FlixelColor)

public void setBgColor(FlixelColor tint)

Sets the background color of this camera.

Parameters:

NameDescription
tintThe background color to set. Must not be null.

ViewportFactory

interface

org.flixelgdx.FlixelCamera.ViewportFactory

public static interface 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)

public Viewport create(int width, int height, Camera camera)

Creates a new Viewport for a camera with the given design dimensions.

Parameters:

NameDescription
widthThe camera's design width in game pixels.
heightThe camera's design height in game pixels.
cameraThe libGDX camera this viewport will wrap.

Returns: A new Viewport instance. Must not be null.


FollowStyle

enum

org.flixelgdx.FlixelCamera.FollowStyle

public static final enum FollowStyle

Determines how a FlixelCamera follows a FlixelPositional.

Fields

LOCKON

public static final FollowStyle 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

public static final FollowStyle 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

public static final FollowStyle TOPDOWN

The dead zone is centered, allowing free camera movement in all directions. Commonly used in top-down games.


TOPDOWN_TIGHT

public static final FollowStyle TOPDOWN_TIGHT

Like FlixelCamera.TOPDOWN but with a tighter (smaller) dead zone, so the camera follows the target more closely.


SCREEN_BY_SCREEN

public static final FollowStyle 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

public static final FollowStyle NO_DEAD_ZONE

No dead zone. The camera only moves when explicitly scrolled; it does not track the target automatically.


Methods

values()

public static FollowStyle[] values()

valueOf(String)

public static FollowStyle valueOf(String name)

RegionMode

enum

org.flixelgdx.FlixelCamera.RegionMode

public static final enum 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

public static final RegionMode 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

public static final RegionMode 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

public static final RegionMode 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

public static final RegionMode 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.


Methods

values()

public static RegionMode[] values()

valueOf(String)

public static RegionMode valueOf(String name)