Adding Geometries to Game dynamicly

Apr 6, 2010 at 10:45 PM

Im trying to add some Geometries to Game after Game is initialized. But Im confised what method should I use to update the Game.

Here is my xaml:

 <Execution:Game x:Name="SomeGame" Width="800" Height="600">            
            <Execution:Game.Camera>
                <View:Camera x:Name="SomeCamera" Position="50,50,50" Target="0,0,0"/>
            </Execution:Game.Camera>

            <Geometries:Box x:Name="SomeBox01" Dimension="2,2,2" Position="10,0,0" />
            <Geometries:Box x:Name="SomeBox02" Dimension="2,2,2" Position="0,10,0" />
            <Geometries:Box x:Name="SomeBox03" Dimension="2,2,2" Position="0,0,10" />
</Execution:Game>

As you see I have 3 Boxes here, and I want to add more using a Button.

In my click event handler I have this code:

 

Box box = new Box();
box.Dimension = new Coordinate();
box.Dimension.X = 2.0;
box.Dimension.X = 2.0;
box.Dimension.X = 2/0;
box.Position.X = 2.0;
box.Position.Y = 2.0;
box.Position.Z = 2.0;

SomeGame.Children.Add(box);
SomeGame.Scene.AddNode(box);

 

I also tried to call all methods with On... prefix from Game class, but new Boxes don't show up. I noticed than RenderingWorld property of dynamicly added Boxes is set to null. Is there any way to add Boxes dynamicly after Game object is initialized?

 

 

Coordinator
Apr 7, 2010 at 5:50 PM

Hi,

this is something that I really haven't thought of, but a very valid feature I must add. 

I guess the only way that you could sort of work around this is to add all your geometries like you've done with the other boxes, but set the ones you don't want visibile to IsVisible="false". I will however put this feature up on the taskboard and see if I can't get to it soon, as it makes perfect sense to be able to do this. 

 

Apr 8, 2010 at 10:28 AM
Edited Apr 8, 2010 at 10:29 AM

I'm not exactly sure if I get this right, but I have tried something like adding a mesh with a button and it worked.

public partial class MyGame : Game
{
       public void AddMesh(Mesh _myMesh)
        {
            Scene.AddNode(_myMesh);
        }
}

private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
// Generating a complete mesh in code behind
Mesh mesh = GenerateSphereMesh();
_myGame.AddMesh(mesh);
}

Mar 16, 2012 at 7:03 PM

using

game.Scene.addNode(newBox)/

game.scene.removeNode(newBox)

instead of

game.Children.add(newBox)/

game.Children.Remove(newBox),

that worked as Canard described.