Code on Lazarus with TCastle2DControl

Nor can not deal with TCastle2DControl, nedujus can someone throw good source code examples for the form Lazarus.

TCastle2DControl is a descendant of TCastleControlCustom that includes a ready instance of TCastle2DSceneManager. So you place TCastle2DControl on a form, and you add scenes to the Castle2DControl1.SceneManager.Items, like

procedure TMyForm.FormCreate(...);
var
  MyScene: TCastle2DScene;
begin
  MyScene := TCastle2DScene.Create(Self);
  MyScene.Load('model.x3d');
  MyScene.Translation := Vector3(10, 20, 0);
  Castle2DControl1.SceneManager.Items.Add(MyScene);
end;

Two engine examples that use TCastle2DSceneManager are in engine sources inside

  • examples/2d_dragon_spine_game/
  • examples/physics/physics_2d_game_sopwith/

While they don’t use TCastle2DControl (instead they add TCastle2DSceneManager to a TCastleWindowCustom), but the same things are possible on TCastle2DControl.

Some links to information how to use TCastle2DScene are also on https://github.com/castle-engine/castle-engine/wiki/2D-Games#full-featured-render-using-tcastle2dscene (you’re interested in the links in section " Full-featured: Render using TCastle2DScene").

1 Like