AudioAsset
Ease
FastString
FontAsset
NineSlice
PackedSprite
PackedSpriteID
RB
   HardwareSettings
   IRetroBlitGame
RBAsset
Rect2i
ShaderAsset
SoundReference
SpriteGrid
SpriteSheetAsset
TMXMapAsset
   TMXLayer
   TMXLayerLoadState
   TMXObject
   TMXObjectGroup
   TMXProperties
Vector2i

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

spriteIndex int Sprite index
pos Vector2i Position on display
destRect Rect2i Destination rectangle
flags int Any combination of flags: RB.FLIP_H, RB.FLIP_V, RB.ROT_90_CW, RB.ROT_180_CW, RB.ROT_270_CW, RB.ROT_90_CCW, RB.ROT_180_CCW, RB.ROT_270_CCW.
pivot Vector2i Rotation pivot point, specified as an offset from the sprites top left corner
rotation float Rotation in degrees
spriteName string Sprite name
spriteID PackedSpriteID Sprite SpriteID
sprite PackedSprite Sprite

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() {
    // A sprite sheet with a mixture of tightly packed 32x32 sized sprites
    spriteItems.Load("spritesheets/items");
    spriteItems.grid = new SpriteGrid(new Vector2i(3232));

    // A sprite sheet from a sprite pack
    spriteEffects.Load("spritepacks/effects");

    RB.SpriteSheetSet(spriteEffects);

    explosionSprite = RB.PackedSpriteGet("explosion");
}

void Render() {
    RB.SpriteSheetSet(spriteItems);

    // Draw an item from column 2 and row 4, optionally flipped horizontally
    if (flip) {
        RB.DrawSprite(RB.SpriteIndex(24), pos, RB.FLIP_H);
    } else {
        RB.DrawSprite(RB.SpriteIndex(24), pos);
    }

    RB.SpriteSheetSet(spriteEffects);

    // Draw an explosion sprite from a sprite pack, rotated with the rotation pivot point at its center.
    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