IDE:Lazarus-2.0.2
procedure TForm1.Button1Click(Sender: TObject);
begin
CastleTiledMapControl1.URL := ‘castle-data:/maps/desert.tmx’;
CastleTiledMapControl1.Create(CastleControl1);
//CastleTiledMapControl1.Destroy;
end;
IDE:Lazarus-2.0.2
procedure TForm1.Button1Click(Sender: TObject);
begin
CastleTiledMapControl1.URL := ‘castle-data:/maps/desert.tmx’;
CastleTiledMapControl1.Create(CastleControl1);
//CastleTiledMapControl1.Destroy;
end;
Hi, and welcome!
There are a few issues with your code.
ClassVariable := TClassType.Create(AOwner)
. You shouldn’t call obsolete SomeObject.Create
. You can read more about classes and how they are different from objects in https://castle-engine.io/modern_pascal_introduction.html . I really recommend this book, it’s very simple, yet gives most of the basics you may need.URL
field before the class was created.Destroy
explicitly. It’s automatically called, when the class is freed by FreeAndNil
or ClassVariable.Free
. You can read about that in that book above too.TCastleControl.SceneManager
).TCastleTiledMapControl
to TCastleControl
you should add those to TCastleControl.SceneManager
or TCastleControl.Controls
using InsertFront
, not to TCastleControl
itself.So, your code should be something like:
procedure TForm1.FormCreate(Sender: TObject);
var
MapControl: TCastleTiledMapControl;
begin
MapControl := TCastleTiledMapControl.Create(CastleControl1);
MapControl.URL := 'castle-data:/maps/desert.tmx';
CastleControl1.Controls.InsertFront(MapControl);
end;
thanks to eugeneloza.
IDE:Lazarus-2.02
Castle Game Engine:6.5
CastleControl1 is black,I don’t know how to fix it.
Castle2DControl1 is black,I don’t know how to fix it.
Thanks to the CGE community.
Ah, I’ve forgotten an important thing. To view the whole map, you have to set MapControl.FullSize := true;
after creation, this way it will not be a small piece of map (100x100 default), but the map will take the whole area of CastleControl
.
The reason why you had the “control is black” is because the colored map was actually higher than the are covered by MapControl, so it only rendered background piece (i.e. black).
One note about your code: do not insert one MapControl
(or anything else) into two different CastleControl
s (like CastleControl1
and Castle2DControl1
in your code), it may misbehave.
Believe in the power of the community
Author: a contributor & Google Translate
When faced with a problem,
It took no whole night to find the answer all day long.
Publish the problem to the community,
It will take a few hours,
There are people from unknown countries, unknown genders, strangers who have never met,
Give you the most satisfactory answer.
No need to pay,
No transactions,
No need to pay,
No transactions,
I want to be a devotee like that!
IDE:Lazarus-2.0.2
Castle-Engine:6.5
Build
Target OS:Win64
Target CPU family:x86_64
It Works!
Build
Target OS:Win32
Target CPU family:i386
It doesn’t work.
@edit.games Fixed! Thanks for reporting this.
And thanks for publishing https://github.com/edit-games/EmbedTiledInForm on GitHub – it was trivial to reproduce the problem thanks to this example. Indeed the error was only on win32. I remade the relevant code to use AnsiString all the way, it’s now simpler and the error is gone
The fixed engine version is immediately available from GitHub, on https://github.com/castle-engine/castle-engine/ . The 6.5 snapshot on https://castle-engine.io/ wil also be automatically updated (but this will take a few hours).