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); }; } }
/// <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; }
/// <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); } }
/// <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); }
public Sprite(Image sprite, Transformation transformation, SATCollisionVolume collider) : this(sprite, transformation, null, collider) { }
/// <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) { }
/// <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()) { }
/// <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) { }
/// <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) { }
public Transformation(Transformation old) : this(old.Position, old.Scale, old.Rotation, old.Pivot) { Depth = old.Depth; }
/// <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; }
/// <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; }
public DrawCommand(Texture2D source, Transformation transformation) { this.source = source; this.transformation = transformation; this.destination = null; }
public DrawCommand(Texture2D source, Transformation transformation, RenderTarget2D destination) { this.source = source; this.transformation = transformation; this.destination = destination; }