Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Sprite.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 
5 using SiliconStudio.Core.Mathematics;
6 using SiliconStudio.Core.Serialization.Converters;
7 
8 namespace SiliconStudio.Paradox.Graphics
9 {
10  /// <summary>
11  /// A sprite represents a series frames in an atlas forming an animation.
12  /// </summary>
13  [DataConverter(AutoGenerate = true, ContentReference = false)]
14  public class Sprite : ImageFragment
15  {
16  /// <summary>
17  /// Creates a new instance of sprite with unique random name.
18  /// </summary>
19  public Sprite()
20  : this(Guid.NewGuid().ToString())
21  {
22  }
23 
24  /// <summary>
25  /// Create a new instance of sprite.
26  /// </summary>
27  /// <param name="fragmentName">the sprite name</param>
28  public Sprite(string fragmentName)
29  : base(fragmentName)
30  {
31  }
32 
33  /// <summary>
34  /// The position of the center of the image in pixels.
35  /// </summary>
36  [DataMemberConvert]
37  public Vector2 Center;
38 
39  /// <summary>
40  /// Draw a specific frame of the sprite with white color and scale of 1.
41  /// </summary>
42  /// <param name="spriteBatch">The sprite batch used to draw the sprite.</param>
43  /// <param name="position">The position to which draw the sprite</param>
44  /// <param name="rotation">The rotation to apply on the sprite</param>
45  /// <param name="depthLayer">The depth layer to which draw the sprite</param>
46  /// <param name="spriteEffects">The sprite effect to apply on the sprite</param>
47  /// <remarks>This function must be called between the <see cref="SpriteBatch.Begin(SiliconStudio.Paradox.Graphics.SpriteSortMode,SiliconStudio.Paradox.Graphics.Effect)"/>
48  /// and <see cref="SpriteBatch.End()"/> calls of the provided <paramref name="spriteBatch"/></remarks>
49  /// <exception cref="ArgumentException">The provided frame index is not valid.</exception>
50  /// <exception cref="ArgumentOutOfRangeException">The provided spriteBatch is null</exception>
51  public void Draw(SpriteBatch spriteBatch, Vector2 position, float rotation = 0, float depthLayer = 0, SpriteEffects spriteEffects = SpriteEffects.None)
52  {
53  Draw(spriteBatch, position, Color.White, Vector2.One, rotation, depthLayer, spriteEffects);
54  }
55 
56  /// <summary>
57  /// Draw a specific frame of the sprite.
58  /// </summary>
59  /// <param name="spriteBatch">The sprite batch used to draw the sprite.</param>
60  /// <param name="position">The position to which draw the sprite</param>
61  /// <param name="color">The color to use to draw the sprite</param>
62  /// <param name="rotation">The rotation to apply on the sprite</param>
63  /// <param name="scales">The scale factors to apply on the sprite</param>
64  /// <param name="depthLayer">The depth layer to which draw the sprite</param>
65  /// <param name="spriteEffects">The sprite effect to apply on the sprite</param>
66  /// <remarks>This function must be called between the <see cref="SpriteBatch.Begin(SiliconStudio.Paradox.Graphics.SpriteSortMode,SiliconStudio.Paradox.Graphics.Effect)"/>
67  /// and <see cref="SpriteBatch.End()"/> calls of the provided <paramref name="spriteBatch"/></remarks>
68  /// <exception cref="ArgumentException">The provided frame index is not valid.</exception>
69  /// <exception cref="ArgumentOutOfRangeException">The provided spriteBatch is null</exception>
70  public void Draw(SpriteBatch spriteBatch, Vector2 position, Color color, Vector2 scales, float rotation = 0f, float depthLayer = 0, SpriteEffects spriteEffects = SpriteEffects.None)
71  {
72  if (spriteBatch == null) throw new ArgumentNullException("spriteBatch");
73 
74  if(Texture == null)
75  return;
76 
77  spriteBatch.Draw(Texture, position, Region, color, rotation, Center, scales, spriteEffects, Orientation, depthLayer);
78  }
79 
80  /// <summary>
81  /// Clone the current sprite.
82  /// </summary>
83  /// <returns>A new instance of the current sprite.</returns>
84  public Sprite Clone()
85  {
86  return (Sprite)MemberwiseClone();
87  }
88  }
89 }
Represents a two dimensional mathematical vector.
Definition: Vector2.cs:42
void Draw(SpriteBatch spriteBatch, Vector2 position, float rotation=0, float depthLayer=0, SpriteEffects spriteEffects=SpriteEffects.None)
Draw a specific frame of the sprite with white color and scale of 1.
Definition: Sprite.cs:51
Base class for converters to/from a data type.
Sprite(string fragmentName)
Create a new instance of sprite.
Definition: Sprite.cs:28
SpriteEffects
Defines sprite mirroring options.
static readonly Vector2 One
A SiliconStudio.Core.Mathematics.Vector2 with all of its components set to one.
Definition: Vector2.cs:67
Sprite()
Creates a new instance of sprite with unique random name.
Definition: Sprite.cs:19
Represents a 32-bit color (4 bytes) in the form of RGBA (in byte order: R, G, B, A).
Definition: Color.cs:16
Sprite Clone()
Clone the current sprite.
Definition: Sprite.cs:84
void Draw(SpriteBatch spriteBatch, Vector2 position, Color color, Vector2 scales, float rotation=0f, float depthLayer=0, SpriteEffects spriteEffects=SpriteEffects.None)
Draw a specific frame of the sprite.
Definition: Sprite.cs:70
static readonly Color White
White color.
The text will be centered.
Vector2 Center
The position of the center of the image in pixels.
Definition: Sprite.cs:37
Android.Widget.Orientation Orientation
Definition: Section.cs:9
A sprite represents a series frames in an atlas forming an animation.
Definition: Sprite.cs:14
Base class for texture resources.
Definition: Texture.cs:38