15. Notifications

You can also show on-screen notifications by TCastleNotifications component. This is a TUIControl descendant, so you just create it and add to Window.Controls list, just like other TUIControl descendants mentioned in previous chapters.

You can actually just use the global Notifications instance created for you in the CastleGameNotifications unit (just add it to Window.Controls list). Some engine game features already make notifications to it, and it is also automatically set up to cooperate with CastleScript writeln() function, so you can print to it from VRML/X3D scripts.

// make sure you have these units on "uses" clause:
uses ..., CastleGameNotifications, CastleColors, CastleRectangles;
 
// use this at initialization:
// (adjust anchors and colors to your taste)
Notifications.TextAlignment := hpMiddle;
Notifications.Anchor(hpMiddle);
Notifications.Anchor(vpBottom, 5);
Notifications.Color := Yellow;
Window.Controls.Add(Notifications);
 
// use this whenever you want to show a notification:
Notifications.Show('You picked 10 ammo!');

But you're not forced to use global Notifications from unit CastleGameNotifications. You may as well create your own TCastleNotifications instance, using only CastleNotifications unit. You can ignore our CastleGameNotifications, if you don't like the default notifications.