Exemplo n.º 1
0
        /// <summary>
        /// This method is called every cycle used to update the state of the <see cref="Node"/>.
        /// </summary>
        /// <param name="gameTime">The current game time.</param>
        public virtual void Update(GameTime gameTime)
        {
            bool isDirtyThisFrame = IsDirty;

            if (IsDirty)
            {
                // compute local transform
                LocalTransform = Matrix2.CreateScale(Scale) *
                                 Matrix2.CreateRotationZ(MathHelper.ToRadians(Rotation)) *
                                 Matrix2.CreateTranslation(Position);

                // compute world transform for this node
                if (Parent != null)
                {
                    // compute world transform
                    WorldTransform = LocalTransform * Parent.WorldTransform;
                }
                else
                {
                    // no parent so WorldTransform and LocalTransform are equivalent.
                    WorldTransform = LocalTransform;
                }

                IsDirty = false;
            }

            // update children
            foreach (Node child in Children)
            {
                if (isDirtyThisFrame)
                {
                    child.IsDirty = true;
                }
                child.Update(gameTime);
            }
        }