Skip to content

LevelCompletedNode

LevelCompletedNode (from scenerystack/vegas) is a Panel shown when a player finishes one level of a game: a congratulatory title (which varies with how well they did), a ScoreDisplayStars progress indicator, the level number, the numeric score out of the perfect score, an optional elapsed/best-time readout, and a "Continue" button. All of its content is computed once from plain numbers passed into the constructor — it does not observe live Property values itself (aside from the string Properties it builds internally for i18n).

This is distinct from AllLevelsCompletedNode: LevelCompletedNode reports the result of one level and offers "Continue" (to the next level or back to level selection), whereas AllLevelsCompletedNode is shown once every level in the game has been completed and offers only "Done". A typical game shows LevelCompletedNode after every level, and AllLevelsCompletedNode only after the last one.

ts
import { LevelCompletedNode } from 'scenerystack/vegas';

A minimal example

ts
const levelCompletedNode = new LevelCompletedNode(
  3,        // level
  8,        // score
  10,       // perfectScore
  4,        // numberOfStars
  true,     // timerEnabled
  95,       // elapsedTime, in seconds
  110,      // bestTimeAtThisLevel, in seconds (or null)
  false,    // isNewBestTime
  () => this.showNextLevel(),
  { center: this.layoutBounds.center }
);

this.addChild( levelCompletedNode );

Constructor

ts
new LevelCompletedNode(
  level: number,
  score: number,
  perfectScore: number,
  numberOfStars: number,
  timerEnabled: boolean,
  elapsedTime: number,
  bestTimeAtThisLevel: number | null,
  isNewBestTime: boolean,
  continueFunction: PushButtonListener,
  providedOptions?: LevelCompletedNodeOptions
)
ParameterMeaning
levelThe level number just completed (shown as "Level N" unless levelVisible: false)
score / perfectScoreUsed both for the "Score: N of M" text and to compute the title ("Excellent!"/"Great"/"Good"/"Keep Trying") from score / perfectScore
numberOfStarsPassed to the internal ScoreDisplayStars
timerEnabled, elapsedTime, bestTimeAtThisLevel, isNewBestTimeIf timerEnabled is true, a time readout is shown — with a "Your New Best!" or "Your Best: MM:SS" second line depending on isNewBestTime and whether bestTimeAtThisLevel is non-null
continueFunctionCalled when the "Continue" button is pressed

Options

OptionDefaultEffect
levelVisibletrueWhether the "Level N" line is shown at all
starDiameter62Diameter used to size the inner/outer radii passed to the ScoreDisplayStars' StarNodes
contentMaxWidth400Applied as maxWidth to each child Text/RichText/button individually (not to the Panel's content as a whole)
titleFont / infoFont / buttonFontbold 28px / bold 22px / 26px PhetFontFonts for the title, the info lines (level/score/time), and the "Continue" button
buttonFillPhetColorScheme.BUTTON_YELLOWFill color of the "Continue" button
fill / stroke / cornerRadius (inherited PanelOptions)'rgb(180,205,255)' / 'black' / 35The panel's own background styling

Methods

MemberDescription
dispose()Disposes the internally-created string DerivedStringPropertys and every VBox child (title, stars, level/score/time text, button), then calls Panel.dispose()

The title text is chosen automatically from the score ratio

You don't pass a title string directly — LevelCompletedNode computes score / perfectScore and picks "Excellent!" (>0.95), "Great" (>0.75), "Good" (>=0.5), or "Keep Trying" (below that) for you. If you need different thresholds or wording, you'll need to build a custom results panel rather than configuring this one; there's no option to override the title text or its breakpoints.