Skip to content

Sprite

namespace Griff.Scenes;
public sealed class Sprite : Component, IDrawable, INetState

Draws an image (or a solid rectangle when no image is set) at the entity’s transform.

This is a component: its saved properties are on its component page.

public int Columns { get; set; }

For sprite sheets: frames across the image. 1 for a single image.

public Color FlashOverlay { get; }

The color painted over the sprite right now by Flash, with its alpha saying how much (0 none, 1 all of it). The image’s shape and transparency are kept.

public bool FlipX { get; set; }

Draws the image mirrored left to right (movement components flip it to face the way they go).

public bool FlipY { get; set; }

Draws the image upside down.

public int Frame { get; set; }

Which frame to show, counting left to right, top to bottom from 0.

public Vector4 FrameRect { get; }

The part of the image to show for Frame: (u, v, width, height) in 0–1 image space.

public string? Image { get; set; }

Image path relative to the project’s Assets folder, e.g. “Sprites/player.png”.

public bool IsBlinkedOut { get; }

True while Blink has the sprite in its hidden half.

public int Order { get; set; }

Higher draws on top. Ties are broken by Z position, then hierarchy order.

public int Rows { get; set; }

For sprite sheets: frames down the image.

public Vector2 Size { get; set; }

Size in world units before the transform’s scale.

public float Slice { get; set; }

For panels and buttons that stretch (nine-slice): how much of the image, from 0 to 0.5 of its width and height, is border at each edge. Corners then keep their shape at any Size, edges stretch one way and the middle fills the rest. 0 stretches the whole image.

public float SliceSize { get; set; }

With Slice: how big the border is drawn, in world units (never more than half the sprite).

public Color Tint { get; set; }

Multiplies the image’s colors: white leaves it as it is, and a lower alpha fades it.

public void AdvanceEffects(float seconds)

Moves Flash and Blink on by seconds. Called by the game.

public void Blink(float seconds, float rate = 12f)

Hides and shows the sprite rate times a second for seconds, like a hero who can’t be hurt again just yet. Starts hidden; 0 seconds stops blinking.

public ValueTuple<Color, Color> Drawn(StepBlend blend)

Its Tint and FlashOverlay in a frame drawn as blend says: part way through a fade or flash between steps.

public void Flash(Color? color = default, float seconds = 0.1f)

Paints the sprite color (white by default) for seconds, fading out over the second half: the classic flash when something is hit. A new flash replaces one in progress.

public IEnumerable<ValueTuple<Matrix4x4, Vector4>> Pieces()

The quads the sprite is drawn with, in the world, and the part of its image on each: one, or nine for a Sliced sprite (corners, edges, middle; left to right, top to bottom).