Programmatically adding Geometry after initialization

Oct 17, 2010 at 5:45 PM


The following code adds a new Box to a Game:

MyGame.Children.Add(new Box()
                Dimension = new Coordinate(5, 5, 5),
                Position = new Coordinate(20, 10, 10)

If I use this in the code that initializes my Silverlight app, it works fine; a box is displayed on the screen.

However, if I put this code in a event handler the box is not displayed after the event is raised. Is there a method that needs to be called to actually render it? Am I misunderstanding something here?

Thank you. Great engine by the way!

Oct 17, 2010 at 9:41 PM

Hi and thanks,

so, just to get everything right. You have for instance a Button and on the Click event you create a box and add it and that doesn't work? Or is it another event. 
Must admit I haven't actually tried, but a scenario Balder _MUST_ support, so If thats the case - I'll have a look at it. 

Theres been an issue that might be around this, but I've been barking up the wrong tree completely.

Oct 17, 2010 at 10:14 PM

It's actually the MouseLeftButtonUp event from the Game itself. I've made a small test project that demonstrates the problem. You can download it here.

Also worth mentioning is that I use version

Thanks for your help.

Oct 18, 2010 at 1:07 PM

I didn't quite read your code correctly, which would have saved some time - sorry about that. 

The problem is that you're adding it to the Children collection - you need to do the following : 

MyGame.Scene.AddNode(new Box.....)

That'll work.

Oct 18, 2010 at 7:05 PM

Although that seems a bit unintuitive, it works! Thanks!

Oct 18, 2010 at 8:10 PM

Agree.. I'll be certain to hide children and make it private, its not supposed to be used.

Oct 18, 2010 at 8:11 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Oct 19, 2010 at 7:17 PM

I've been using Children.Add to add child geometries to other geometries, but when I called Children.Remove, it doesn't seem to be releasing all the references.  So, based off this thread, I've tried using this.Scene.AddNode (from within custom Geometries that were placed in the Game in XAML) but I'm finding that this.Scene is always null.  Is there a special way to put a geometry in the game in XAML to make sure Scene gets wired up?

Oct 19, 2010 at 9:42 PM

You should use Scane.RemoveNode() that will clean it up.

Adding a child to another geometry and removing it from that geometry should clean things up.


Its a shame I didn't notice that Children property on Game being exposed earlier - its a really confusing thing for the API