class Sprite
A Sprite is an image that’s set up for direct 2D rendering, without using a mesh or model! This is technically a wrapper over a texture, but it also includes atlasing functionality, which can be pretty important to performance! This is used a lot in UI, for image rendering.
Atlasing is not currently implemented, it’ll swap to Single for now. But here’s how it works!
StereoKit will batch your sprites into an atlas if you ask it to! This puts all the images on a single texture to significantly reduce draw calls when many images are present. Any time you add a sprite to an atlas, it’ll be marked as dirty and rebuilt at the end of the frame. So it can be a good idea to add all your images to the atlas on initialize rather than during execution!
Since rendering is atlas based, you also have only one material per atlas. So this is why you might wish to put a sprite in one atlas or another, so you can apply different
Instance Fields and Properties
float Aspect | The aspect ratio of the sprite! This is width/height. You may also be interested in the NormalizedDimensions property, which are normalized to the 0-1 range. |
int Height | Height of the sprite, in pixels. |
string Id | Gets or sets the unique identifier of this asset resource! This can be helpful for debugging, managine your assets, or finding them later on! |
Vec2 NormalizedDimensions | Width and height of the sprite, normalized so the maximum value is 1. |
int Width | Width of the sprite, in pixels. |
Instance Methods
Draw | Draw the sprite on a quad with the provided transform! |
Static Fields and Properties
Sprite ArrowDown | This is a 64x64 image of a slightly rounded triangle pointing down. |
Sprite ArrowLeft | This is a 64x64 image of a slightly rounded triangle pointing left. |
Sprite ArrowRight | This is a 64x64 image of a slightly rounded triangle pointing right. |
Sprite ArrowUp | This is a 64x64 image of a slightly rounded triangle pointing up. |
Sprite Backspace | This is a 64x64 image of a backspace action button, similar to a backspace button you might find on a mobile keyboard. |
Sprite Close | This is a 64x64 image of a square aspect X, with rounded edge. It’s used to indicate a ‘close’ icon. |
Sprite RadioOff | This is a 64x64 image of an empty hole. This is common iconography for radio buttons which use an empty hole to indicate an un-selected radio, and a filled hole for a selected radio. This is used by the UI for radio buttons! |
Sprite RadioOn | This is a 64x64 image of a filled hole. This is common iconography for radio buttons which use an empty hole to indicate an un-selected radio, and a filled hole for a selected radio. This is used by the UI for radio buttons! |
Sprite Shift | This is a 64x64 image of an upward facing rounded arrow. This is a triangular top with a narrow rectangular base, and is used to indicate a ‘shift’ icon on a keyboard. |
Sprite ToggleOff | This is a 64x64 image of an empty rounded square. This is common iconography for checkboxes which use an empty square to indicate an un-selected checkbox, and a filled square for a selected checkbox. This is used by the UI for toggle buttons! |
Sprite ToggleOn | This is a 64x64 image of a filled rounded square. This is common iconography for checkboxes which use an empty square to indicate an un-selected checkbox, and a filled square for a selected checkbox. This is used by the UI for toggle buttons! |
Static Methods
Find | Finds a sprite that matches the given id! Check out the DefaultIds static class for some built-in ids. Sprites will auto-id themselves using this pattern if single sprites: {Tex.Id}/spr, and this pattern if atlased sprites: atlas_spr/{atlas}/{Tex.Id}. |
FromFile | Create a sprite from an image file! This loads a Texture from file, and then uses that Texture as the source for the Sprite. |
FromTex | Create a sprite from a Texture object! |
Found an issue with these docs, or have some additional questions? Create an Issue on Github!