hgeSprite

Sprite class for rendering textured quads.

Overview

The hgeSprite class represents a rectangular region of a texture that can be rendered to the screen. Sprites support rotation, scaling, color tinting, and various blend modes.

Creating a Sprite

// From a texture and coordinates
HTEXTURE tex = hge->Texture_Load("player.png");
hgeSprite *sprite = new hgeSprite(tex, 0, 0, 64, 64);

// Set the rotation/scale center
sprite->SetHotSpot(32, 32);

Rendering

bool RenderFunc()
{
    hge->Gfx_BeginScene();
    hge->Gfx_Clear(0);
    
    // Simple render
    sprite->Render(100, 100);
    
    // With rotation (in radians)
    sprite->RenderEx(200, 100, 0.5f);
    
    // With rotation and scale
    sprite->RenderEx(300, 100, 0.5f, 2.0f, 2.0f);
    
    hge->Gfx_EndScene();
    return false;
}

Methods

Rendering Methods

  • Render(x, y) — Draw at position
  • RenderEx(x, y, rot, hscale, vscale) — Draw with transformation
  • RenderStretch(x1, y1, x2, y2) — Draw stretched to rectangle
  • Render4V(...) — Draw with four arbitrary vertices

Property Methods

  • SetHotSpot(x, y) — Set rotation/position center
  • SetBlendMode(mode) — Set blending operation
  • SetColor(color, i) — Set vertex color
  • SetFlip(bX, bY, bHotSpot) — Mirror horizontally/vertically
  • SetTexture(tex) — Change the texture
  • SetTextureRect(x, y, w, h) — Change texture region
  • SetZ(z, i) — Set Z-order

Query Methods

  • GetTexture() — Get current texture handle
  • GetTextureRect(&x, &y, &w, &h) — Get texture coordinates
  • GetColor(i) — Get vertex color
  • GetZ(i) — Get Z value
  • GetWidth() — Get sprite width
  • GetHeight() — Get sprite height
  • GetBoundingBox(x, y, &rect) — Get axis-aligned bounds
  • GetBoundingBoxEx(...) — Get transformed bounds

Blend Modes

Sprites support various blend modes for different visual effects:

sprite->SetBlendMode(BLEND_COLORMUL | BLEND_ALPHABLEND);

See Blend Mode Constants for all options.

See Also