This project is read-only.

Checking every bullet instance

Jan 22, 2013 at 3:08 PM


I'm kind of stuck with checking ALL my bullets in the game.
The bullets are created by a component, which adds an instance of a template. 
All these components are not in the Game Solution, but in my Data library.

A part of my shooter component:

private void OnKeyDown(object sender, KeyboardEventArgs e)
            if (e.Key == Trigger && allowShooting)
                shotTimer = 0;

                var Player = Parent.FindName<Nine.Graphics.Model>("mmm");
                var PlayerPosition = Parent.FindName<Transformable>("Jon");

                var bullet = new Instance() { Template = BulletTemplate };
                // We take the position of the group that the player is in and the rotation of the model,
                // with this I take groups rotation and multipy it with the players position
                bullet.Transform = Player.Transform * Matrix.CreateTranslation(PlayerPosition.Transform.Translation);

                allowShooting = false;


My bullet component:

public class RapidBullet : Component
        private float lifetime;

        public float BulletSpeed { get; set; }
        public TimeSpan Duration { get; set; }

        protected override void Update(float elapsedTime)
            lifetime += elapsedTime;
            if (lifetime > Duration.TotalSeconds)

            var transform = Parent.Transform;
            transform.Translation += transform.Forward * BulletSpeed * elapsedTime;
            Parent.Transform = transform;

My bullet template:

<Group Name="bullet"

    <ParticleEffect Name="Fireball" Texture="{ContentReference ../fire}" Transform.Position="0, 10, 0">
            <SphereEmitter Emission="1000" Duration="0.1" Speed="2" Size="100" Shell="True" Radius="0.5"/>

        <SizeController EndSize ="4 ~ 5" />
        <SpeedController EndSpeed ="0" />
        <FadeController />

    <Sphere Name="Kogel" Visible="False" Transform.Position="0,10,15" Transform.Scale="10,10,10"/>

    <my:RapidBullet BulletSpeed="400" Duration="00:00:01.0"/> 


I can check the Model/Particle used in the Scene, by using scene.Find etc. But this will only check the first bullet shot.
I can have like 5 fireballs alive at the same moment because of timers, it's a piece of gameplay.

How can I check every instance of this bullet? 


Jan 23, 2013 at 1:23 AM

use Scene.Traverse

Jan 23, 2013 at 12:38 PM

Thanks, however I have just created new Bullets in my Bullet.XAML, so I'll try this later on.

Another quick question.

I have the Bullet.xaml, which is a Group, but in the Group I've declared multiple groups.
But I'm not succeeding in removing such a Group.
This is how it looks like, roughly:

<Group Name="bullet"

    <Group Name="Fireball1group">

How can I remove the 'Fireball1Group' group with scene.Remove?
I've tried to scene.FindName<Group>("Fireball1Group"), but it's not working. :(

Am I doing something wrong? 

Jan 24, 2013 at 3:23 AM

The remove method can only remove the child that is directly attached to the scene.

To remove "Fireball1group" in your case, first find the “bullet” group, then remove the fireball using sth like:

var fireball = scene.FindName<Group>("Fireball1group"); fireball.Parent.Remove(fireball);