|
RB.DrawSprite
Method - Static
public static void DrawSprite(int spriteIndex, Vector2i pos)
|
public static void DrawSprite(int spriteIndex, Rect2i destRect)
|
public static void DrawSprite(int spriteIndex, Vector2i pos, int flags = 0)
|
public static void DrawSprite(int spriteIndex, Rect2i destRect, int flags = 0)
|
public static void DrawSprite(int spriteIndex, Vector2i pos, Vector2i pivot, float rotation)
|
public static void DrawSprite(int spriteIndex, Rect2i destRect, Vector2i pivot, float rotation)
|
public static void DrawSprite(int spriteIndex, Vector2i pos, Vector2i pivot, float rotation, int flags = 0)
|
public static void DrawSprite(int spriteIndex, Rect2i destRect, Vector2i pivot, float rotation, int flags = 0)
|
public static void DrawSprite(string spriteName, Vector2i pos)
|
public static void DrawSprite(string spriteName, Rect2i destRect)
|
public static void DrawSprite(string spriteName, Vector2i pos, int flags = 0)
|
public static void DrawSprite(string spriteName, Rect2i destRect, int flags = 0)
|
public static void DrawSprite(string spriteName, Vector2i pos, Vector2i pivot, float rotation)
|
public static void DrawSprite(string spriteName, Rect2i destRect, Vector2i pivot, float rotation)
|
public static void DrawSprite(string spriteName, Vector2i pos, Vector2i pivot, float rotation, int flags = 0)
|
public static void DrawSprite(string spriteName, Rect2i destRect, Vector2i pivot, float rotation, int flags = 0)
|
public static void DrawSprite(FastString spriteName, Vector2i pos)
|
public static void DrawSprite(FastString spriteName, Rect2i destRect)
|
public static void DrawSprite(FastString spriteName, Vector2i pos, int flags = 0)
|
public static void DrawSprite(FastString spriteName, Rect2i destRect, int flags = 0)
|
public static void DrawSprite(FastString spriteName, Vector2i pos, Vector2i pivot, float rotation)
|
public static void DrawSprite(FastString spriteName, Rect2i destRect, Vector2i pivot, float rotation)
|
public static void DrawSprite(FastString spriteName, Vector2i pos, Vector2i pivot, float rotation, int flags = 0)
|
public static void DrawSprite(FastString spriteName, Rect2i destRect, Vector2i pivot, float rotation, int flags = 0)
|
public static void DrawSprite(PackedSpriteID spriteID, Vector2i pos)
|
public static void DrawSprite(PackedSpriteID spriteID, Rect2i destRect)
|
public static void DrawSprite(PackedSpriteID spriteID, Vector2i pos, int flags = 0)
|
public static void DrawSprite(PackedSpriteID spriteID, Rect2i destRect, int flags = 0)
|
public static void DrawSprite(PackedSpriteID spriteID, Vector2i pos, Vector2i pivot, float rotation)
|
public static void DrawSprite(PackedSpriteID spriteID, Rect2i destRect, Vector2i pivot, float rotation)
|
public static void DrawSprite(PackedSpriteID spriteID, Vector2i pos, Vector2i pivot, float rotation, int flags = 0)
|
public static void DrawSprite(PackedSpriteID spriteID, Rect2i destRect, Vector2i pivot, float rotation, int flags = 0)
|
public static void DrawSprite(PackedSprite sprite, Vector2i pos)
|
public static void DrawSprite(PackedSprite sprite, Rect2i destRect)
|
public static void DrawSprite(PackedSprite sprite, Vector2i pos, int flags = 0)
|
public static void DrawSprite(PackedSprite sprite, Rect2i destRect, int flags = 0)
|
public static void DrawSprite(PackedSprite sprite, Vector2i pos, Vector2i pivot, float rotation)
|
public static void DrawSprite(PackedSprite sprite, Rect2i destRect, Vector2i pivot, float rotation)
|
public static void DrawSprite(PackedSprite sprite, Vector2i pos, Vector2i pivot, float rotation, int flags = 0)
|
public static void DrawSprite(PackedSprite sprite, Rect2i destRect, Vector2i pivot, float rotation, int flags = 0)
|
Parameters
Returns
Nothing.
Description
Draw a sprite from the current sprite sheet as set by RB.SpriteSheetSet. There are many overloads of this method to fit different needs.
The destination position of the drawn sprite is specified with pos, or destRect. When using destRect the destination size could be different than the source sprite size, which allows for scaling the sprite to any size.
Sprites can be drawn from two sources with RB.DrawSprite, either with a spriteIndex of a sprite in a sprite sheet, or with a sprite from a sprite pack specified with spriteName, spriteID or sprite.
Sprite specified by sprite index
When drawing by sprite index the current sprite sheet should be laid out in a grid fashion, with each sprite being the same size. The sprite size can be specified when setting up the sprite sheet with SpriteSheetAsset. The sprite index represents the cell number in this sprite grid, with the top left being index 0. The indices increase in a row-major order, meaning the index to the right of 0 is 1, and the index below 0 is equal to count of columns in a row.
The convenience method RB.SpriteIndex can be used to calculate a sprite index given the row and column.
Sprite specified by packed sprite
When drawing with packed sprites the current sprite sheet must have been created by SpriteSheetAsset with a sprite pack. Packed sprites can be specified by their name which corresponds to the source filename of the unpacked sprite, or by their PackedSprite or PackedSpriteID representation.
When using packed sprites it is more optimal to pre-fetch sprite IDs with PackedSpriteGet or PackedSpriteID to avoid a relatively expensive string hashing operation behind the scenes.
Optional parameters
Optional parameter flags allows for flipping the sprite horizontally or vertically by using RB.FLIP_H and RB.FLIP_V respectively. The RB.ROT_90_CW flag can be used to rotate the sprite by 90 degrees. A combination of these flags can be used to rotate and flip in any cardinal direction, for convenience these combinations are provided:
For arbitrary rotations the pivot parameter can specify the rotation center (offset from the sprites top-left corner), and the rotation parameter can specify any angle in degrees.
Example
SpriteSheetAsset
spriteItems; SpriteSheetAsset spriteEffects;
PackedSprite explosionSprite;
void Initialize() { spriteItems.Load("spritesheets/items"); spriteItems.grid = new SpriteGrid(new Vector2i(32, 32));
spriteEffects.Load("spritepacks/effects");
RB.SpriteSheetSet(spriteEffects);
explosionSprite = RB.PackedSpriteGet("explosion"); }
void Render() { RB.SpriteSheetSet(spriteItems);
if (flip) { RB.DrawSprite(RB.SpriteIndex(2, 4), pos, RB.FLIP_H); } else { RB.DrawSprite(RB.SpriteIndex(2, 4), pos); }
RB.SpriteSheetSet(spriteEffects);
RB.DrawSprite( explosionSprite, pos, new Vector2i(explosionSprite.Size.width / 2, explosionSprite.Size.height / 2), (int)RB.Ticks() % 360); } |
See Also
RB.DrawCopy
RB.DrawNineSlice
RB.SpriteSheetSet
SpriteSheetAsset
See Docs
Features - Drawing
Features - Sprite Sheets
Features - Sprite Packs
|