Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: ViewComponent

[18:7] extends: Component

Wraps FXGL's ViewComponent (com.almasb.fxgl.entity.components.ViewComponent), the component that holds an entity's visual children — child Nodes, opacity, z-index, visibility, and the JavaFX event pipeline that fires on the view's parent Group. Reachable through Entity.getViewComponent() or the Entity-level convenience methods (addViewNode, removeViewNode, setView).

Methods

  • ViewComponent ()

    Creates a new empty ViewComponent.

  • adopt (object Ajo)

    Wraps an existing ViewComponent AussomJavaObject.

  • addChild (object NodeObj)

    Adds a child Node to the view (transforms applied).

  • addChildNoTransform (object NodeObj)

    Adds a child Node to the view without applying the entity's scale / rotate transforms. Use for HUD-like overlays that should track position but ignore rotation.

  • getChild (int Index)

    Returns the child Node at the given index. Returns a raw AJO — the caller can adopt it into the appropriate Node-subclass wrapper.

  • removeChild (object NodeObj)

    Removes a child Node from the view.

  • clearChildren ()

    Removes every child Node.

  • getChildren ()

    Returns the children as an ObservableList AJO.

  • getParent ()

    Returns the underlying view-root Parent AJO.

  • isVisible ()

    Returns whether the view is visible.

  • setVisible (bool Visible)

    Sets whether the view is visible.

  • getOpacity ()

    Returns the current opacity (0.0 - 1.0).

  • setOpacity (double Opacity)

    Sets the opacity.

  • opacityProperty ()

    Returns the opacity DoubleProperty for binding.

  • visibleProperty ()

    Returns the BooleanProperty backing visibility.

  • getZIndex ()

    Returns the z-index that drives draw-order sorting.

  • setZIndex (int Z)

    Sets the z-index that drives draw-order sorting. Higher values draw on top.

  • zIndexProperty ()

    Returns the IntegerProperty for the z-index.

  • addEventHandler (object EventTypeAjo, callback Cb)

    Registers a JavaFX EventHandler for the given event type on this view. The Aussom callback receives the raw event AJO; the return value is ignored.

    • @p EventTypeAjo is a javafx.event.EventType (use the static constants on the event class, e.g. MouseEvent.MOUSE_PRESSED).
    • @p Cb is a callback (eventAjo) -> any.
    • @r The handler AJO so it can later be removed with removeEventHandler.
  • removeEventHandler (object EventTypeAjo, object HandlerAjo)

    Removes a previously registered EventHandler. Pass the EventType and the same handler AJO that was returned by addEventHandler — each aji.closure call creates a new proxy, so an inline callback cannot be removed.

  • addOnClickHandler (callback Cb)

    Registers a click handler on this view (shortcut for addEventHandler with MouseEvent.MOUSE_CLICKED). The Aussom callback receives the raw MouseEvent AJO.

    • @p Cb is a callback (mouseEventAjo) -> any.
    • @r The handler AJO so it can later be removed with removeOnClickHandler.
  • removeOnClickHandler (object HandlerAjo)

    Removes a previously registered click handler. Pass the handler AJO returned by addOnClickHandler.

  • addDevChild (object NodeObj)

    Attaches a dev-only Node to the view (used by debug overlays such as the BBox visualizer). The node is layered above the normal children and does not participate in regular layout.

  • removeDevChild (object NodeObj)

    Detaches a Node previously added via addDevChild.