Sprite ClassDelta Engine Documentation
2D sprite to be rendered, which is an image or animation or sprite sheet used as an Entity2D. View code on GitHub
Inheritance Hierarchy

System Object
  DeltaEngine.Entities Entity
    DeltaEngine.Entities DrawableEntity
      DeltaEngine.Rendering2D Entity2D
        DeltaEngine.Rendering2D HierarchyEntity2D
          DeltaEngine.Rendering2D Sprite
            Asteroids Asteroid
            Asteroids PlayerShip
            Blocks Brick
            Breakout Ball
            Breakout Paddle
            CarGame2D Car
            CarGame2D Game
            DeltaEngine.Scenes.Controls Control
            DeltaNinja.Entities MovingSprite
            DeltaNinja.UI LogoLink
            FindTheWord StartupScreen
            GameOfDeath FadeSprite
            GameOfDeath.Items Item
            GameOfDeath Rabbit
            GhostWars Tree
            LogoApp BouncingLogo
            SideScroller Plane
            TilDeath Background
            TilDeath Enemy
            TilDeath HeroDeath

Namespace: DeltaEngine.Rendering2D
Assembly: DeltaEngine.Rendering2D (in DeltaEngine.Rendering2D.dll) Version: 1.1.1.0 (1.1.1)
Syntax

public class Sprite : HierarchyEntity2D

The Sprite type exposes the following members.

Constructors

  NameDescription
Protected methodSprite 
Initializes a new instance of the Sprite class
Public methodSprite(String, Rectangle)
Initializes a new instance of the Sprite class
Public methodSprite(String, Vector2D)
Initializes a new instance of the Sprite class
Public methodSprite(Material, Rectangle)
Initializes a new instance of the Sprite class
Public methodSprite(Material, Vector2D)
Initializes a new instance of the Sprite class
Top
Methods

  NameDescription
Public methodAdd(HierarchyObject2D) (Inherited from HierarchyEntity2D.)
Public methodAdd T (T) (Overrides Entity2D Add T (T).)
Public methodAddTag (Inherited from Entity.)
Public methodClearTags (Inherited from Entity.)
Public methodContains T  (Inherited from Entity2D.)
Public methodContainsBehavior T  (Inherited from Entity.)
Public methodContainsTag (Inherited from Entity.)
Protected methodDeactivate (Inherited from Entity.)
Public methodDispose (Inherited from Entity.)
Public methodGet T  (Overrides Entity2D Get T  .)
Protected methodGetActiveBehaviors (Inherited from Entity.)
Public methodGetComponentsForEditing (Inherited from Entity2D.)
Protected methodGetComponentsForSaving (Overrides Entity2D GetComponentsForSaving .)
Protected methodGetDrawBehaviors (Inherited from DrawableEntity.)
Public methodGetFirstChildOfType T  (Inherited from HierarchyEntity2D.)
Public methodGetInterpolatedArray T  (Inherited from DrawableEntity.)
Public methodGetInterpolatedList T  (Inherited from DrawableEntity.)
Public methodGetOrDefault T  (Inherited from Entity.)
Public methodGetTags (Inherited from Entity.)
Protected methodNextUpdateStarted (Overrides Entity2D NextUpdateStarted .)
Public methodOnDraw T  (Inherited from DrawableEntity.)
Protected methodOnPositionChanged (Inherited from HierarchyEntity2D.)
Protected methodOnRotationChanged (Inherited from HierarchyEntity2D.)
Public methodRemove(HierarchyObject2D) (Inherited from HierarchyEntity2D.)
Public methodRemove T   (Inherited from Entity.)
Public methodRemoveTag (Inherited from Entity.)
Public methodReset
Public methodRotatedDrawAreaContains (Inherited from Entity2D.)
Public methodSet (Overrides Entity2D Set(Object).)
Public methodSetComponents (Inherited from Entity.)
Public methodSetWithoutInterpolation T  (Overrides Entity2D SetWithoutInterpolation T (T).)
Public methodStart T  (Inherited from Entity.)
Public methodStop T  (Inherited from Entity.)
Public methodToggleVisibility (Inherited from DrawableEntity.)
Public methodToString (Inherited from Entity.)
Public methodUpdateGlobalsFromParent (Inherited from HierarchyEntity2D.)
Top
Extension Methods

  NameDescription
Public Extension MethodAffixToPhysics (Defined by Entity2DPhysicsExtensions.)
Public Extension MethodStartBouncingOffScreenEdges (Defined by Entity2DExtensions.)
Public Extension MethodStartFalling (Defined by Entity2DExtensions.)
Public Extension MethodStartMoving (Defined by Entity2DExtensions.)
Public Extension MethodStartMovingUV (Defined by Entity2DExtensions.)
Public Extension MethodStartRotating (Defined by Entity2DExtensions.)
Top
Fields

  NameDescription
Protected fieldcomponents (Inherited from Entity.)
Protected fieldlastTickLerpComponents
Each element can either be a Lerp, a Lerp List or an array of Lerp objects. View code on GitHub
(Inherited from DrawableEntity.)
Top
Properties

  NameDescription
Public propertyAlpha (Inherited from Entity2D.)
Public propertyBlendMode
Public propertyCenter (Inherited from Entity2D.)
Public propertyChildren (Inherited from HierarchyEntity2D.)
Public propertyColor (Inherited from Entity2D.)
Public propertyCurrentFrame
Public propertyDidFootprintChange (Inherited from Entity2D.)
Public propertyDrawArea (Inherited from Entity2D.)
Public propertyElapsed
Public propertyFlipMode
Public propertyIsActive (Inherited from HierarchyEntity2D.)
Public propertyIsPauseable (Inherited from Entity.)
Public propertyIsPlaying
Public propertyIsVisible (Inherited from DrawableEntity.)
Public propertyLastColor (Inherited from Entity2D.)
Public propertyLastDrawArea (Inherited from Entity2D.)
Public propertyLastUV
Public propertyMaterial
Public propertyNumberOfComponents (Inherited from Entity.)
Public propertyParent (Inherited from HierarchyEntity2D.)
Public propertyRelativePosition (Inherited from HierarchyEntity2D.)
Public propertyRelativeRotation (Inherited from HierarchyEntity2D.)
Public propertyRenderLayer (Inherited from DrawableEntity.)
Public propertyRotation (Inherited from Entity2D.)
Public propertyRotationCenter (Inherited from Entity2D.)
Public propertySize (Inherited from Entity2D.)
Public propertyTopLeft (Inherited from Entity2D.)
Public propertyUpdatePriority (Inherited from Entity.)
Public propertyUV
Top
Events

  NameDescription
Public eventAnimationEnded
Top
Remarks

Tests: DeltaEngine.Rendering2D.Tests.SpriteSaveAndLoadTests
Examples

43 unit tests call DeltaEngine.Rendering2D.Sprite
[Test, CloseAfterFirstFrame]
public void CreateSpriteFromComponents()
{
    var components = new List<object>();
    components.Add(Rectangle.One);
    components.Add(true);
    var material = new Material(ShaderFlags.Position2DTextured, "DeltaEngineLogo");
    components.Add(material);
    components.Add(material.DiffuseMap.BlendMode);
    components.Add(new RenderingData());
    var sprite = Activator.CreateInstance(typeof(Sprite),
        BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, Type.DefaultBinder,
        null, CultureInfo.CurrentCulture) as Sprite;
    sprite.SetComponents(components);
    Assert.AreEqual(material, sprite.Material);
    Assert.AreEqual(Rectangle.One, sprite.DrawArea);
    Assert.AreEqual(material.DiffuseMap.BlendMode, sprite.BlendMode);
}
[Test, CloseAfterFirstFrame]
public void SaveAndLoadSprite()
{
    var sprite = new Sprite("DeltaEngineLogo", Rectangle.One);
    var data = BinaryDataExtensions.SaveToMemoryStream(sprite);
    Assert.Greater(data.Length, 0);
    var loadedSprite = data.CreateFromMemoryStream() as Sprite;
    Assert.AreEqual(sprite.Material.Shader, loadedSprite.Material.Shader);
    Assert.AreEqual(sprite.Material.DiffuseMap, loadedSprite.Material.DiffuseMap);
    Assert.AreEqual(sprite.DrawArea, loadedSprite.DrawArea);
    Assert.AreEqual(sprite.BlendMode, loadedSprite.BlendMode);
    Assert.AreEqual(sprite.Rotation, loadedSprite.Rotation);
    Assert.AreEqual(1, loadedSprite.GetActiveBehaviors().Count);
    Assert.AreEqual(1, loadedSprite.GetDrawBehaviors().Count);
    Assert.AreEqual("SpriteRenderer",
        loadedSprite.GetDrawBehaviors()[0].GetShortNameOrFullNameIfNotFound());
}
[Test, ApproveFirstFrameScreenshot]
public void RenderAnimatedSprite()
{
    new Sprite(material, new Rectangle(0.4f, 0.4f, 0.2f, 0.2f));
}
See Also