Defines spatial properties for art assets
Пример #1
0
        public Sprite(Image sprite, Transformation transformation, AnimationScript animation, SATCollisionVolume collider)
        {
            this.Image = sprite;
            SubRect = new Rectangle(0, 0, sprite.Texture.Width, sprite.Texture.Height);

            this.Transformation = new Transformation(transformation);
            this.AnimationScript = animation;
            this.CollisionVolume = collider;

            OnDraw += this.Draw;

            if (CollisionVolume != null)
            {
                OnUpdate += delegate(GameTime time) { collider.TransformCollisionVolume(this.Transformation); };
            }
        }
Пример #2
0
        /// <summary>
        /// Converts a point in local object coordinate space into world coordinates
        /// </summary>
        /// <param name="translation"></param>
        /// <param name="objectPoint">A point in object coordinate space. 0,0 = lower left corner of object</param>
        /// <param name="worldPosition">The object's pivot position in world space</param>
        /// <returns></returns>
        public static Vector2 ObjectToWorld(Transformation transformation, Vector2 objectPoint, bool horizontalFlip)
        {
            if (horizontalFlip == true)
                transformation.Scale *= new Vector2(-1, 1);
            Matrix rotation = Matrix.CreateRotationZ(-transformation.Rotation);
            Matrix scale = Matrix.CreateScale(new Vector3(transformation.Scale, 1));
            if (horizontalFlip == true)
                transformation.Scale *= new Vector2(-1, 1);

            Matrix compositeTransformationMatrix = rotation * scale;

            Vector2 offset = objectPoint - transformation.Pivot;
            offset = Vector2.Transform(offset, compositeTransformationMatrix);

            Vector2 worldPoint = transformation.Position + offset;

            return worldPoint;
        }
Пример #3
0
        /// <summary>
        /// Draws this sprite using the given transformation and depth
        /// </summary>
        /// <param name="transformation">The transformation to apply to the sprite</param>
        /// <param name="depth">A depth value, from 0.0 (back) to 1.0 (front).</param>
        /// <param name="sourceRectangle">Subrectangle on the sprite generated by ProcessAnimation. Contains a single frame of the sprite sheet.</param>
        /// <remarks>If on a layer, depth only applies within that layer.</remarks>
        internal void Draw(Transformation transformation, Rectangle? sourceRectangle)
        {
            if (sourceRectangle.HasValue)
            {
                Rectangle texelRect = sourceRectangle.Value;

                ZeplinGame.spriteBatch.Draw(texture, new Vector2(transformation.Position.X, -transformation.Position.Y), texelRect,
                    color, transformation.Rotation, transformation.Pivot, transformation.Scale, Facing, transformation.Depth);
            }
            else
            {
                ZeplinGame.spriteBatch.Draw(texture, new Vector2(transformation.Position.X, -transformation.Position.Y), null,
                    color, transformation.Rotation, transformation.Pivot, transformation.Scale, Facing, transformation.Depth);
            }
        }
Пример #4
0
 /// <summary>
 /// Draws this sprite using the given transformation and depth
 /// </summary>
 /// <param name="transformation">The transformation to apply to the sprite</param>
 /// <remarks>If on a layer, depth only applies within that layer.</remarks>
 internal void Draw(Transformation transformation)
 {
     Draw(transformation, null);
 }
Пример #5
0
 public Sprite(Image sprite, Transformation transformation, SATCollisionVolume collider)
     : this(sprite, transformation, null, collider)
 {
 }
Пример #6
0
 /// <summary>
 /// Constructs a tile with a sprite and a transformation
 /// </summary>
 /// <param name="sprite"></param>
 /// <param name="transformation"></param>
 public Sprite(Image sprite, Transformation transformation)
     : this(sprite, transformation, null, null)
 {
 }
Пример #7
0
 /// <summary>
 /// An Actor can be drawn on screen, translated around arbitrarily, collide with other game objects, and process update logic every frame.
 /// </summary>
 /// <param name="sprite">The artwork the actor will use during Draw.</param>
 /// <param name="transformation">Positioning information.</param>
 public Actor(Image sprite, Transformation transformation)
     : this(sprite, transformation, new SATCollisionVolume())
 {
 }
Пример #8
0
 /// <summary>
 /// An Actor can be drawn on screen, translated around arbitrarily, collide with other game objects, and process update logic every frame.
 /// </summary>
 /// <param name="sprite">The artwork the actor will use during Draw.</param>
 /// <param name="transformation">Positioning information.</param>
 /// <param name="collider">A collision shape that mirrors the transformation.</param>
 public Actor(Image sprite, Transformation transformation, SATCollisionVolume collider)
     : base(sprite, transformation, collider)
 {
 }
Пример #9
0
 /// <summary>
 /// Constructs a tile with a sprite and a transformation
 /// </summary>
 /// <param name="sprite"></param>
 /// <param name="transformation"></param>
 public Tile(Sprite sprite, Transformation transformation)
     : this(sprite, transformation, null, null)
 {
 }
Пример #10
0
 public Transformation(Transformation old)
     : this(old.Position, old.Scale, old.Rotation, old.Pivot)
 {
     Depth = old.Depth;
 }
Пример #11
0
 /// <summary>
 /// Creates a MenuItem with a Sprite and Transformation
 /// </summary>
 /// <param name="sprite"></param>
 /// <param name="transformation"></param>
 public MenuItem(Sprite sprite, Transformation transformation)
 {
     this.Sprite = sprite;
     this.Transformation = transformation;
 }
Пример #12
0
 /// <summary>
 /// Creates a MenuItem with a Sprite and Transformation
 /// </summary>
 /// <param name="spriteResource">A path to an art resource</param>
 /// <param name="transformation"></param>
 public MenuItem(String spriteResource, Transformation transformation)
 {
     this.Sprite = new Sprite(spriteResource);
     this.Transformation = transformation;
 }
Пример #13
0
 public DrawCommand(Texture2D source, Transformation transformation)
 {
     this.source = source;
     this.transformation = transformation;
     this.destination = null;
 }
Пример #14
0
 public DrawCommand(Texture2D source, Transformation transformation, RenderTarget2D destination)
 {
     this.source = source;
     this.transformation = transformation;
     this.destination = destination;
 }