In more involved cases, you should use multiple views within your control. In this case, use TCastleView
within the TCastleControl
, and load a design (file xxx.castle-user-interface
) inside the view using TCastleView.DesignUrl
. This is analogous to our recommended workflow with TCastleWindow
. You can add new view using CGE editor ("Code → New Unit → View…"), or just define a new unit like this:
unit GameViewMain;
interface
uses CastleUIControls;
type
TViewMain = class(TCastleView)
published
public
constructor Create(AOwner: TComponent); override;
procedure Start; override;
end;
var
ViewMain: TViewMain;
implementation
constructor TViewMain.Create(AOwner: TComponent);
begin
inherited;
DesignUrl := 'castle-data:/gameviewmain.castle-user-interface';
end;
procedure TViewMain.Start;
begin
inherited;
end;
end.
That’s enough to load gameviewmain.castle-user-interface
design from your data
subdirectory.
To initialize this view in your application, you can use this code e.g. in OnCreate
form event:
ViewMain := TViewMain.Create(Application);
MyCastleControl.Container.View := ViewMain;
A simple example of using views with TCastleControl
is in examples/lazarus/multiple_views. The CGE API used there is the same for Lazarus (LCL) and Delphi (VCL, FMX) versions of TCastleControl
.