Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: Viewport

[18:7] extends: FxObj

Wraps FXGL's Viewport (com.almasb.fxgl.app.scene.Viewport), the camera frame for a GameScene. The viewport controls which part of the game world is rendered: panning, following an entity, zoom, rotation, screen-shake, and fade / flash overlays all live here. Aussom users hold a Viewport wrapper via adopt after obtaining one from the running GameScene (typically fxgl.getGameScene().getViewport).

Methods

  • Viewport (InitialWidth = null, double InitialHeight = 0.0)

    Creates a new Viewport with the given size. Pass null for InitialWidth to construct an empty wrapper for adopt.

    • @p InitialWidth is the viewport width in pixels, or null.
    • @p InitialHeight is the viewport height in pixels.
  • adopt (object Ajo)

    Wraps an existing Viewport AussomJavaObject.

    • @p Ajo is an AussomJavaObject around a Viewport.
    • @r A new wrapper.
  • xProperty ()

    Returns the read-only origin-X property.

    • @r An AussomJavaObject around a ReadOnlyDoubleProperty.
  • yProperty ()

    Returns the read-only origin-Y property.

    • @r An AussomJavaObject around a ReadOnlyDoubleProperty.
  • getX ()

    Returns the current origin X.

    • @r A double.
  • setX (double X)

    Sets the current origin X.

    • @p X is the new origin X.
    • @r this object
  • getY ()

    Returns the current origin Y.

    • @r A double.
  • setY (double Y)

    Sets the current origin Y.

    • @p Y is the new origin Y.
    • @r this object
  • getOrigin ()

    Returns the current viewport origin as a Point2D.

    • @r An AussomJavaObject around a Point2D.
  • getVisibleArea ()

    Returns the currently visible viewport area as a Rectangle2D (origin plus zoom-scaled width / height).

    • @r An AussomJavaObject around a Rectangle2D.
  • getZoom ()

    Returns the current zoom factor (1.0 = no zoom).

    • @r A double.
  • setZoom (double Zoom)

    Sets the zoom factor.

    • @p Zoom is the new zoom factor (>1 zooms in, <1 zooms out).
    • @r this object
  • zoomProperty ()

    Returns the zoom DoubleProperty for binding.

    • @r An AussomJavaObject around a SimpleDoubleProperty.
  • getAngle ()

    Returns the current viewport rotation in degrees.

    • @r A double.
  • setAngle (double Angle)

    Sets the viewport rotation in degrees.

    • @p Angle is the new rotation.
    • @r this object
  • angleProperty ()

    Returns the rotation DoubleProperty for binding.

    • @r An AussomJavaObject around a SimpleDoubleProperty.
  • getWidth ()

    Returns the current viewport width in pixels.

    • @r A double.
  • setWidth (double W)

    Sets the viewport width in pixels.

    • @p W is the new width.
    • @r this object
  • widthProperty ()

    Returns the width DoubleProperty for binding.

    • @r An AussomJavaObject around a SimpleDoubleProperty.
  • getHeight ()

    Returns the current viewport height in pixels.

    • @r A double.
  • setHeight (double H)

    Sets the viewport height in pixels.

    • @p H is the new height.
    • @r this object
  • heightProperty ()

    Returns the height DoubleProperty for binding.

    • @r An AussomJavaObject around a SimpleDoubleProperty.
  • isLazy ()

    Returns whether the viewport follows its bound entity lazily (smoothed, asymptotic) rather than instantly.

    • @r A bool.
  • setLazy (bool Lazy)

    Sets the lazy-follow flag.

    • @p Lazy is the new flag value.
    • @r this object
  • isFloating ()

    Returns whether the viewport applies a noise-driven floating offset (gives a hand-held camera feel).

    • @r A bool.
  • setFloating (bool Floating)

    Sets the floating-camera flag.

    • @p Floating is the new flag value.
    • @r this object
  • getCamera ()

    Returns the visual-effects camera Entity. Effects (like the flash overlay) attach to this entity's ViewComponent.

    • @r An AussomJavaObject around an Entity.
  • bindToEntity (object EntityObj, double DistX, double DistY)

    Binds the viewport origin to follow a target entity at a fixed offset.

    • @p EntityObj is an Entity wrapper.
    • @p DistX is the X offset between origin and entity.
    • @p DistY is the Y offset between origin and entity.
    • @r this object
  • bindToFit (double XMargin, double YMargin, object EntitiesObj)

    Binds the viewport to fit every given entity inside its frame, scaling the zoom to make them fit and translating to keep them centered (with optional margins).

    • @p XMargin is the horizontal margin in pixels.
    • @p YMargin is the vertical margin in pixels.
    • @p EntitiesObj is an AussomJavaObject around an Entity varargs array (or a single Entity).
    • @r this object
  • unbind ()

    Releases any viewport entity binding and zoom binding.

    • @r this object
  • setBounds (int MinX, int MinY, int MaxX, int MaxY)

    Sets the world bounds the viewport will not move past when following an entity.

    • @p MinX is the minimum X.
    • @p MinY is the minimum Y.
    • @p MaxX is the maximum X.
    • @p MaxY is the maximum Y.
    • @r this object
  • focusOnEntity (object EntityObj)

    Centers the viewport on the given entity's center.

    • @p EntityObj is an Entity wrapper.
    • @r this object
  • focusOn (double X, double Y)

    Centers the viewport on the given (X, Y) world point.

    • @p X is the focus X.
    • @p Y is the focus Y.
    • @r this object
  • shake (double PowerTranslate, double PowerRotate)

    Applies a combined translational and rotational shake for the given powers.

    • @p PowerTranslate is the translational shake power.
    • @p PowerRotate is the rotational shake power.
    • @r this object
  • shakeTranslational (double Power)

    Applies a translational-only shake for the given power.

    • @p Power is the shake magnitude.
    • @r this object
  • shakeRotational (double Power)

    Applies a rotational-only shake for the given power.

    • @p Power is the rotation magnitude.
    • @r this object
  • flash (callback Cb)

    Triggers a white-screen flash overlay that fades out. The supplied callback runs when the fade finishes.

    • @p Cb is a callback with no arguments.
    • @r this object
  • fade (callback Cb)

    Triggers a fade-to-black overlay that fades in. The supplied callback runs when the fade finishes.

    • @p Cb is a callback with no arguments.
    • @r this object
  • onUpdate (double Tpf)

    Drives the viewport's per-frame logic (shake, fade / flash, bound-entity origin tracking). Normally invoked by the GameScene update loop; only call manually for standalone Viewport use.

    • @p Tpf is the per-frame time in seconds.
    • @r this object