An Embarcadero blog entry just released covers this: blog
Cloning objects in C++ Firemonkey platform
-
05-03-2022 - |
Question
I'm creating (for learning purposes) a 2D game in embarcadero's Firemonkey XE2 platform. It's a game similar to space invanders in terms of visual representation of the game field but vastly more complex.
I'm trying to spawn animated enemies. I created a template TImage and assigned it a BitmapListAnimation with six pictures. Then i just clone it using Clone(). Here is the cloning code:
virtual void CreateMe(TForm* pForm);
void CBaseEnemy::CreateMe(TForm *pForm)
{
TImage* pSource = dynamic_cast<TImage*>(this->pToClone);
pSource->Visible = true;
TImage* pDest = dynamic_cast<TImage*>(pSource->Clone(pForm));
pDest->Parent = pForm;
TBitmapListAnimation* pAnimSource = dynamic_cast<TBitmapListAnimation*>(pForm->FindComponent("BitmapListAnimation1"));
pAnimSource->Parent = pDest;
pAnimSource->Start();
TBitmapListAnimation* pAnimDest = dynamic_cast<TBitmapListAnimation*>(pAnimSource->Clone(pForm));
}
And it works, It's just extremely complicated, could you suggest a way to clone an entire template (A Component such as TImage along with all it's children) ?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow