Interface FrameListener

All Known Implementing Classes:
Camera, InputManager, WorldNavigationUserInputTracker

public interface FrameListener
Listener interface for per-frame callbacks before the 3D scene is rendered.

Implement this interface and register it with ViewPanel.addFrameListener(FrameListener) to receive a callback before each frame. This is the primary mechanism for implementing animations, physics updates, and other time-dependent behavior.

Usage example - animating a shape:


 viewPanel.addFrameListener((panel, deltaMs) -> {
     // Rotate the shape a little each frame
     double angleIncrement = deltaMs * 0.001;  // radians per millisecond
     myShape.setTransform(new Transform(
         myShape.getLocation(),
         currentAngle += angleIncrement, 0
     ));
     return true;  // request repaint since we changed something
 });
 

The engine uses the return values to optimize rendering: if no listener returns true and no other changes occurred, the frame is skipped to save CPU and energy.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    onFrame(ViewPanel viewPanel, int millisecondsSinceLastFrame)
    Called before each frame render, allowing the listener to update state and indicate whether a repaint is needed.
  • Method Details

    • onFrame

      boolean onFrame(ViewPanel viewPanel, int millisecondsSinceLastFrame)
      Called before each frame render, allowing the listener to update state and indicate whether a repaint is needed.

      Each registered listener is called exactly once per frame tick. The frame is only rendered if at least one listener returns true (or if the view was explicitly marked for repaint).

      Parameters:
      viewPanel - the view panel being rendered
      millisecondsSinceLastFrame - time elapsed since the previous frame, for frame-rate-independent updates
      Returns:
      true if the view should be re-rendered this frame, false if this listener has no visual changes