示例#1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // Initialize the graphics
            _renderer = new Renderer(graphics);

            // Initialize the scene root
            _root = new SceneNode(null, "_root_");

            // Add a test sprite
            SceneNode node = new SceneNode(_root, "Test Node");
            SpriteAttachment spriteAttachment = new SpriteAttachment(node, new Sprite(Content.Load<Texture2D>("sting"), new Vector2(64, 96)));
            node.Position = new Vector2(200.0f, 200.0f);

            base.Initialize();
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="owner"></param>
 /// <param name="sprite"></param>
 public SpriteAttachment(SceneNode owner, Sprite sprite)
     : base(owner)
 {
     _sprite = sprite;
 }
 /// <summary>
 /// Processes a collision to the scene node
 /// </summary>
 /// <param name="gameTime">Elapsed game time</param>
 /// <param name="collider">The object colliding with the node</param>
 public virtual void OnCollision(GameTime gameTime, SceneNode collider)
 {
 }
        protected SceneNode _owner; // Node that owns this attachment

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="_owner">Node that owns this attachment</param>
        public SceneNodeAttachment(SceneNode owner)
        {
            Owner = owner;
        }
        private Vector2 _position = Vector2.Zero; // Location of the centre of the scene node

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="parent">Parent node</param>
        /// <param name="name">Name of the node</param>
        public SceneNode(SceneNode parent, String name)
            : base(parent)
        {
            _name = name;
            _attachments = new List<SceneNodeAttachment>();
        }
 /// <summary>
 /// Processes a collision with the scene node
 /// </summary>
 /// <param name="gameTime">Elapsed game time</param>
 public virtual void OnCollision(GameTime gameTime, SceneNode collider)
 {
     // Notify all attachments of the collision
     foreach (SceneNodeAttachment attachment in _attachments)
     {
         attachment.OnCollision(gameTime, collider);
     }
 }