Notifications

You can show on-screen notifications by TCastleNotifications user interface control (TUIControl descendant).

You can just create an instance of this class, and add it to the Window.Controls list, as you do with any other UI control. But you can also use the global Notifications instance already created for you in the CastleGameNotifications unit (just add it to Window.Controls list). Some engine components already make notifications to it, and it is also automatically set up to cooperate with the CastleScript writeln() function, so you can print to it from VRML/X3D scripts.

uses CastleWindow, CastleGameNotifications, CastleColors, CastleUIControls;
 
var
  Window: TCastleWindow;
begin
  Window := TCastleWindow.Create(Application);
 
  Notifications.TextAlignment := hpMiddle;
  Notifications.Anchor(hpMiddle);
  Notifications.Anchor(vpBottom, 10);
  Notifications.Color := Yellow;
  Window.Controls.InsertFront(Notifications);
 
  Notifications.Show('You picked 10 ammo!');
 
  Window.OpenAndRun;
end.

Remember that you're not forced to use the global Notifications from unit CastleGameNotifications, especially if you don't like the default notifications. You may always create your own TCastleNotifications instance, using only the CastleNotifications unit.