You have to insert instances of scenes into a viewport (more precisely,
TCastleViewport.Items tree) to make them actually visible.
TCastleViewport represents a 2D viewport on a screen, within this viewport your world (3D or 2D) is displayed. Viewport is a user interface control, which means that it descends from
TCastleUserInterface and it shares the same feature we’ve seen in the previous chapter about views and UI.
If you like to learn by watching, this is good introduction to viewport capabilities in 3D and 2D:
You can add there any classes descending from
TCastleTransform. We list the most important classes and their properties below.
Use the base
TCastleTransform class to transform and group the children.
TCastleScene is the most important class to display 3D and 2D models.
It can render, animate, perform collisions etc. Set
URL to load the model. Run animation using
TCastleScene descends from
TCastleTransform. So you can also use
Scale to transform it. Scene can even have children. Use
ExposeTransforms to attach children to animated bones in glTF skeleton.
TCastleText allows to display a text, possibly transformed in 3D.
All of them have a configurable size,
Material (set to
pmUnlit to easily make it brighter),
Texture and other basics. While you could create such simple objects in any 3D authoring software (and use them through
TCastleScene as well), our primitives are often very useful for quickly prototyping your game world.
TCastleImageTransform allows to display an image inside a viewport. This is great for simple static 2D game backgrounds, that should move along with player or camera. The image has a configurable pivot, it can be repeated and resized in an easy way.
TCastleTransformReference makes a reference to another
TCastleTransform (e.g. a single scene, or a group of scenes) to instantiate it again within the same viewport. This is an efficient way to create a lot of instances of the same object. At the end of Tutorial: Designing a 3D world we have a quick section describing how to use it.
TCastleTransformReference.Reference to indicate which transformation is referenced by this instance.
Navigation is our term to describe a class handling user input to move the camera. Our engine provides some ready navigation classes, for example
TCastleWalkNavigation implementing a typical navigation in FPS games. But you don’t have to use our ready navigation classes, you can easily just move the camera with your own code.
Now that you know the basic terminology and classes, let’s see how to actually use them.
Next chapters will start by describing how to use them in our visual editor, and later we’ll show examples how to use them from Pascal. Remember that everything you do inside the editor can be done by Pascal code too. In particular, all the classes and their properties that you use within the editor are really the same classes you use from Pascal code. So whatever you can change from editor — you can also later change during the game, from code. And all the class instances that you create within the editor (like
TCastleScene) — can also be created (or destroyed) in any order during the game execution.
To improve this documentation just edit the source of this page in AsciiDoctor (simple wiki-like syntax) and create a pull request to Castle Game Engine WWW (cge-www) repository.