This G2DComponent already has a parent

Mar 30, 2011 at 10:03 PM

Hi all,

I'm facing this issue don't know yet how to fix it.


I write an application that use G2DPanel as:

G2DPanel frame = new G2DPanel();

frame.Bounds = new Rectangle(250, 0, 250, 500);
frame.Border = GoblinEnums.BorderFactory.LineBorder;
frame.Transparency = 0.5f;  // Range from 0 (Fully transparent) to 1 (fullly opaque)

//Add this frame to the scence as


//Create two labels initially as:

G2DLabel labelX = new G2DLabel("ABC");

labelX.TextFont = uiFont;
labelX.TextColor = Color.Blue;
labelX.Bounds = new Rectangle(5, 10, 250, 20);

G2DLabel labelY = new G2DLabel("DEF");

labelY.TextFont = uiFont;
labelY.TextColor = Color.Blue;
labelY.Bounds = new Rectangle(5, 20, 250, 20);

The text in these two labels are changing as use click on a button.... there is code for this section. I want to add these two label sto the frame as

protected override void Update(GameTime gameTime)





Then, I run the code in debug mode, an exception is thrown out saying:

"This G2DComponent already has a parent" at the line contain "frame.AddChild(labelY);" in Update method.

I did check and this labelY doesn't assigned any parent yet. It seems that it doesn't allow me to add the second G2DComponent to G2DPanel?. Because when I switch the order in update method as 



Then the error is at the second line containing "frame.AddChild(labelX);".


Any idea how to fix this or did I do something wrong here?