Sprite |
public class SpriteBatch : IDisposable
The SpriteBatch type exposes the following members.
Name | Description | |
---|---|---|
AreAbsoluteCoordinatesSupported | Gets a Boolean that specifies if this SpriteBatch supports absolute coordinates (true when created from SceneView; false when created from Scene). | |
IsUsingAbsoluteCoordinates | Gets or sets a Boolean that specifies if absolute coordinates are used to define positions and sizes (max values are defined by SceneView's size) in the Draw calls that follow the change. When false then relative coordinates are used (in this case the values are from 0 to 1). Absolute coordinates can be used only when this SpriteBatch is created from SceneView and not for Scene (see AreAbsoluteCoordinatesSupported property). This value can be also set when calling Begin(Boolean, Int32) method. Default value is false. | |
IsUsingDpiScale | When set to true (false by default) than the absolute coordinates and sprite size are multiplied by dpi scale. When false, then absolute coordinates are specified in pixels. The value of this property is used for all sprites and texts in this SpriteBatch. |
Name | Description | |
---|---|---|
Begin | Begin method must be called before any Draw or Set calls. The method sets common properties of all sprites that will be defined by Draw call. After all draw calls are done, the End method must be called. | |
CollectRenderingItems | CollectRenderingItems adds the RenderingItem objects to the OverlayRenderingLayer or any custom RenderingLayer that is set in the Begin(Boolean, Int32) method. | |
Dispose | Disposes the resources that are created by this SpriteBatch (does not dispose the used GpuImages). | |
DrawBitmapText(String, Vector2, Single, Color4, Single, Single, Single, Single, Boolean, BitmapTextCreator) | DrawBitmapText method draws the specified text to the specified position that defines the top-left corner of the text. See remarks for more info. | |
DrawBitmapText(String, Vector2, Single, Color4, Color4, Single, Single, Single, Single, Single, Single, Single, Single, Boolean, BitmapTextCreator) | DrawBitmapText method draws the specified text to the specified position that defines the top-left corner of the text. This method also rendered the background with the specified color and applies the specified margin to the text. See remarks for more info. | |
DrawRectangle | DrawRectangle method draws a rectangle at the specified position and size. The rectangle is filled by the specified color. When rotationAngleDegrees is specified (0 by default), then the rectangle is rotated around the center position. | |
DrawSprite(Vector2, Vector2, Single) | DrawSprite method draws the current texture to the specified position, size and and rotation (0 by default). When size is set to (0, 0), then the actual size of the texture is used. See remarks for more info. | |
DrawSprite(Vector2, Single, Single, Single) | DrawSprite method draws the current texture to the specified position and using the specified scale (1 by default) and rotation (0 by default). See remarks for more info. | |
DrawSprite(Vector2, Vector2, Color4, Single, Boolean) | DrawSprite method draws the current texture to the specified position, size and and rotation (0 by default). When size is set to (0, 0), then the actual size of the texture is used. The colors in the texture are multiplied by the specified colorMask. See remarks for more info. | |
DrawSprite(Vector2, Color4, Single, Single, Single, Boolean) | DrawSprite method draws the current texture to the specified position and using the specified scale (1 by default) and rotation (0 by default). The colors in the texture are multiplied by the specified colorMask. See remarks for more info. | |
End | End method ends adding sprites. | |
Finalize |
Destrictor
(Overrides ObjectFinalize) | |
GetBitmapTextSize | Returns the size of the specified text. | |
GetCoordinateCenter | Gets the current position of a coordinate center. See remarks for SetCoordinateCenter(PositionTypes) for more info. | |
SetCoordinateCenter | SetCoordinateCenter can set a custom position of a coordinate center. By default the center position is set to TopLeft, but with this method you can set it to any corner or center of the screen. See remarks for more info. | |
SetSpriteTexture | Sets the specified GpuImage as the current sprite texture | |
SetTransform(Matrix3x2) | Sets the transformation of the sprites that will be drawn after this method is called. Note that the coordinate system goes from (0, 0) at top-left corner to (1, 1) at bottom right corner. To rotate the sprite, set the destinationRectangle in the Draw command so that the center of the sprite will be at (0, 0). | |
SetTransform(Matrix3x2) | Sets the transformation of the sprites that will be drawn after this method is called | |
Update | Update method is automatically called from Scene or SceneView. It sets the Scene or SceneViews dirty flags when any absolute coordinates are used and the SceneView's size is changed. |
Name | Description | |
---|---|---|
Name | Name of this SpriteBatch | |
RenderingLayer | RenderingLayer that will render this SpriteBatch. |
SpriteBatch class defines a collection of sprites (textures) or texts that can be very quickly rendered to the 3D scene.
SpriteBatch objects can be created by calling Scene.CreateBackgroundSpriteBatch(String), Scene.CreateOverlaySpriteBatch(String), SceneView.CreateBackgroundSpriteBatch(String) or SceneView.CreateOverlaySpriteBatch(String). When the SpriteBatch is created from SceneView, then it can use absolute coordinates when calling Draw methods. In this case AreAbsoluteCoordinatesSupported is true and Begin(Boolean, Int32) method can be called with useAbsoluteCoordinates set to true or the IsUsingAbsoluteCoordinates property can be set to true.
To start rendering sprites, first call Begin(Boolean, Int32) method. To draw sprite first call SetSpriteTexture(GpuImage) method and then one or more DrawSprite methods. To draw rectangle call DrawRectangle(Vector2, Vector2, Color4, Single, Boolean) method. To draw text call DrawBitmapText methods (there are overloads with or without a custom BitmapTextCreator and with or without background color with margin). To complete adding sprites call End method.
If you have static and animated sprites or text that changes often, then it is recommended to put static sprites and texts into a one SpriteBatch, and animated sprites and text that change often into another SpriteBatch. This way the RenderingItems for the static SpriteBatch are generated only once and only the animated SpriteBatch needs to recreate its RenderingItems.