The non-visual components registered automatically (and thus available by default in CGE editor) are:
- Fonts: TCastleBitmapFont, TCastleFontFamily, TCastleFont — described in the previous news about fonts.
TCastleSound — describes a sound file to be played. More on this in the upcoming news about sounds and the updated manual chapter about it.
TCastleComponent which is like standard TComponent but it can have non-visual children components managed by TCastleComponent.AddNonVisualComponent method and friends. These “non-visual children components” do not do anything, but they are serialized along with the parent component, thus you can organize your information in a tree.
Oh, and sound and font classes mentioned above also descend from TCastleComponent. And all visual classes, like
TCastleTransformcan have non-visual components too, so e.g. a UI design root, or a
TCastleLabel, can “store” the reference to a font. This is all flexible, so you can use the system to arrange information in any tree you like.
We also have new menu items to create a design that contains only non-visual components:
Design -> New Non-Visual Component (Empty Component As Root) (root is
- Design -> New Non-Visual Component (Custom Root)
E.g. you can use it to store
TCastleSound collection in a file.
An example of using this approach to manage a list of sounds is in examples/fixed_camera_game, the design file data/sounds/all_sounds.castle-component defines all the sounds. The code that handles it is in code/gamesound.pas file. This is our new approach to define a “repository” of sounds, and it will soon be documented prominently in the manual and will deprecate the existing approach to define sound repository by an XML file.
This is our preferred editing and serialization approach for every TComponent. And so our preferred serialization for everything is to use RTTI with TComponent, which makes our CGE editor “complete” in the sense that it is now more universal than only “editor for CGE UI / transforms”, it is now “editor for everything in CGE”.
The non-visual components can be saved / loaded to a file with
TCastleComponent also exposes a nice general mechanism to serialize children lists, using TCastleComponent.CustomSerialization and TSerializationProcess. It is now used to serialize regular children (
TCastleUserInterface children of
TCastleTransform children of
NonVisualComponents children (of any
Behaviors (of any
We also improved related JSON serialization code. It’s now a bit simpler (no more special
$Children code, the
TCastleComponent.CustomSerialization now covers this use-case). We write
$$ClassName earlier (JSON is more readable for humans), we don’ write empty
$Children (JSON simpler for humans).