예제 #1
0
        /// <summary>
        /// By default, draws this GameObject
        /// </summary>
        /// <param name="gameTime">gameTime</param>
        /// <param name="spriteBatch">Active spriteBatch</param>
        /// <param name="depth">Optional depth specification</param>
        /// <param name="origin">Sprite origin point. Default null</param>
        /// <param name="rotation">Rotation</param>
        public virtual void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            //Don't draw if outside camera's bounds
            Camera cam = GameManager.Get("MainCamera") as Camera;

            if (cam != null && !AlwaysDraw)
            {
                if (!cam.Bounds.Intersects(Location))
                {
                    return;
                }
            }


            if (!Active || Texture == null)
            {
                return;
            }

            if (AnimationData == null || !AnimationData.ContainsKey(currentAnimation))
            {
                spriteBatch.Draw(Texture, destinationRectangle: Location, color: DrawColor, effects: SpriteFX, origin: Origin, rotation: Rotation);
            }
            else
            {
                AnimationData[currentAnimation].Draw(spriteBatch);
            }
        }
예제 #2
0
        /// <summary>
        /// What do to every frame
        /// </summary>
        /// <param name="gameTime">gameTime</param>
        public virtual void Update(GameTime gameTime)
        {
            if (!Active || !CanUpdate)
            {
                return;
            }

            //Change the velocity by acceleration
            Velocity.X += Acceleration.X;
            Velocity.Y += Acceleration.Y;

            //Then change the displacement by velocity
            Location.X += (int)(Velocity.X * gameTime.ElapsedGameTime.TotalSeconds * 100);
            Location.Y += (int)(Velocity.Y * gameTime.ElapsedGameTime.TotalSeconds * 100);

            //Make sure this can be animated
            if (AnimationData == null)
            {
                return;
            }
            if (AnimationData.ContainsKey(currentAnimation))
            {
                AnimationData[currentAnimation].Update(gameTime);
            }
        }
예제 #3
0
 /// <summary>
 /// Add a new animation that can be able to be played by name
 /// </summary>
 /// <param name="newAnimation"></param>
 public void AddAnimation(Animate newAnimation)
 {
     if (AnimationData.ContainsKey(newAnimation.Name))
     {
         AnimationData[newAnimation.Name] = newAnimation;
     }
     else
     {
         AnimationData.Add(newAnimation.Name, newAnimation);
     }
 }
예제 #4
0
 /// <summary>
 /// Change to a new animation and play it.
 /// The Animation MUST have been added before you try to play it by name!
 /// </summary>
 /// <param name="animationName">Name of the new animation</param>
 public void ChangeAnimation(string animationName)
 {
     if (!AnimationData.ContainsKey(animationName))
     {
         Console.WriteLine("Animation not found!");
     }
     else
     {
         //If we change to the same animation, no need to change anything
         if (currentAnimation == animationName)
         {
             return;
         }
         currentAnimation = animationName;
         AnimationData[currentAnimation].Reset();
     }
 }