Skip to content

Sprite

Info

Dependencies:
- PermMem
Implementation:
Sprite.d on GitHub

Sprite package implements functions for working with 2D sprites.

Initialization

Initialize with LeGo_Sprite flag.

LeGo_Init(LeGo_Sprite);

Functions

Sprite_Create

Sprite_Create

Creates a sprite. The dimensions are in virtual coordinates.

func int Sprite_Create(var int x, var int y, var int width, var int height, var int color, var string tex)
Parameters
  • var int x
    X position of sprite (virtual)
  • var int y
    Y position of sprite (virtual)
  • var int width
    Width of sprite (virtual)
  • var int height
    Height of sprite (virtual)
  • var int color
    Color of sprite (in RGBA format)
  • var string tex
    Name of the sprite texture

Return value

The function returns the handle of the created sprite.

Sprite_CreatePxl

Sprite_CreatePxl

Creates a sprite. The dimensions are in pixels.

func int Sprite_CreatePxl(var int x, var int y, var int width, var int height, var int color, var string tex)
Parameters
  • var int x
    X position of sprite (pixels)
  • var int y
    Y position of sprite (pixels)
  • var int width
    Width of sprite (pixels)
  • var int height
    Height of sprite (pixels)
  • var int color
    Color of sprite (in RGBA format)
  • var string tex
    Name of the sprite texture

Return value

The function returns the handle of the created sprite.

Sprite_Render

Sprite_Render

Renders a sprite on a screen (must be visible first).

func void Sprite_Render(var int h)
Parameters
  • var int h
    Handle of the sprite

Sprite_SetVisible

Sprite_SetVisible

Sets the visibility of a sprite.

func void Sprite_SetVisible(var int h, var int visible)
Parameters
  • var int h
    Handle of the sprite
  • var int visible
    Visibility flag (0 for invisible, 1 for visible)

Sprite_SetPrio

Sprite_SetPrio

Sets the priority of a sprite. The higher the priority, the closer the sprite is to the camera.

func void Sprite_SetPrio(var int h, var int prio)
Parameters
  • var int h
    Handle of the sprite
  • var int prio
    Priority of the sprite

Sprite_Scale

Sprite_Scale

Scales a sprite.

func void Sprite_Scale(var int h, var int x, var int y)
Parameters
  • var int h
    Handle of the sprite
  • var int x
    X scale factor (as ikarus float)
  • var int y
    Y scale factor (as ikarus float)

Sprite_SetWidth

Sprite_SetWidth

Sets the width of a sprite in virtual coordinates.

func void Sprite_SetWidth(var int h, var int w)
Parameters
  • var int h
    Handle of the sprite
  • var int w
    Width of the sprite in virtual coordinates

Sprite_SetWidthPxl

Sprite_SetWidthPxl

Sets the width of a sprite in pixels.

func void Sprite_SetWidthPxl(var int h, var int w)
Parameters
  • var int h
    Handle of the sprite
  • var int w
    Width of the sprite in pixels

Sprite_SetHeight

Sprite_SetHeight

Sets the height of a sprite in virtual coordinates.

func void Sprite_SetHeight(var int h, var int hg)
Parameters
  • var int h
    Handle of the sprite
  • var int hg
    Height of the sprite in virtual coordinates

Sprite_SetHeightPxl

Sprite_SetHeightPxl

Sets the height of a sprite in pixels.

func void Sprite_SetHeightPxl(var int h, var int hg)
Parameters
  • var int h
    Handle of the sprite
  • var int hg
    Height of the sprite in pixels

Sprite_SetDim

Sprite_SetDim

Sets the dimensions of a sprite in virtual coordinates.

func void Sprite_SetDim(var int h, var int w, var int hg)
Parameters
  • var int h
    Handle of the sprite
  • var int w
    Width of the sprite in virtual coordinates
  • var int hg
    Height of the sprite in virtual coordinates

Sprite_SetDimPxl

Sprite_SetDimPxl

Sets the dimensions of a sprite in pixels.

func void Sprite_SetDimPxl(var int h, var int w, var int hg)
Parameters
  • var int h
    Handle of the sprite
  • var int w
    Width of the sprite in pixels
  • var int hg
    Height of the sprite in pixels

Sprite_SetPos

Sprite_SetPos

Sets the position of a sprite in virtual coordinates.

func void Sprite_SetPos(var int h, var int x, var int y)
Parameters
  • var int h
    Handle of the sprite
  • var int x
    X position of the sprite (virtual)
  • var int y
    Y position of the sprite (virtual)

Sprite_SetPosPxl

Sprite_SetPosPxl

Sets the position of a sprite in pixels.

func void Sprite_SetPosPxl(var int h, var int x, var int y)
Parameters
  • var int h
    Handle of the sprite
  • var int x
    X position of the sprite (pixels)
  • var int y
    Y position of the sprite (pixels)

Sprite_SetPosPxlF

Sprite_SetPosPxlF

Sets the position of a sprite in pixels (floating point).

func void Sprite_SetPosPxlF(var int h, var int xf, var int yf)
Parameters
  • var int h
    Handle of the sprite
  • var int xf
    X position of the sprite (pixels but as a float)
  • var int yf
    Y position of the sprite (pixels but as a float)

Sprite_SetColor

Sprite_SetColor

Sets the color of a sprite.

func void Sprite_SetColor(var int h, var int col)
Parameters
  • var int h
    Handle of the sprite
  • var int col
    Color of the sprite (in RGBA format)

Sprite_SetVertColor

Sprite_SetVertColor

Sets the color of a vertex in a sprite.

func void Sprite_SetVertColor(var int h, var int vert, var int col)
Parameters
  • var int h
    Handle of the sprite
  • var int vert
    Index of the vertex (0-3)
  • var int col
    Color of the vertex (in RGBA format)

Sprite_SetUV

Sprite_SetUV

Sets the UV coordinates of a sprite.

func void Sprite_SetUV(var int h, var int x0, var int y0, var int x1, var int y1)
Parameters
  • var int h
    Handle of the sprite
  • var int x0
    X coordinate of the top-left UV
  • var int y0
    Y coordinate of the top-left UV
  • var int x1
    X coordinate of the bottom-right UV
  • var int y1
    Y coordinate of the bottom-right UV

Sprite_SetVertUV

Sprite_SetVertUV

Sets the UV coordinates of a vertex in a sprite.

func void Sprite_SetVertUV(var int h, var int vert, var int x, var int y)
Parameters
  • var int h
    Handle of the sprite
  • var int vert
    Index of the vertex (0-3)
  • var int x
    X coordinate of the UV
  • var int y
    Y coordinate of the UV

Sprite_Rotate

Sprite_Rotate

Rotates a sprite by a given angle in degrees.

func void Sprite_Rotate(var int h, var int r)
Parameters
  • var int h
    Handle of the sprite
  • var int r
    Rotation angle in degrees

Sprite_RotateR

Sprite_RotateR

Rotates a sprite by a given angle in radians.

func void Sprite_RotateR(var int h, var int r)
Parameters
  • var int h
    Handle of the sprite
  • var int r
    Rotation angle in radians

Sprite_SetRotation

Sprite_SetRotation

Sets the rotation of a sprite in degrees.

func void Sprite_SetRotation(var int h, var int r)
Parameters
  • var int h
    Handle of the sprite
  • var int r
    Rotation angle in degrees

Sprite_SetRotationR

Sprite_SetRotationR

Sets the rotation of a sprite in radians.

func void Sprite_SetRotationR(var int h, var int r)
Parameters
  • var int h
    Handle of the sprite
  • var int r
    Rotation angle in radians

Sprite_SetRotationSC

Sprite_SetRotationSC

Sets the rotation of a sprite using sine and cosine values.

func void Sprite_SetRotationSC(var int h, var int sin, var int cos)
Parameters
  • var int h
    Handle of the sprite
  • var int sin
    Sine value of the rotation
  • var int cos
    Cosine value of the rotation

Helper functions

SinCosApprox

SinCosApprox

Approximates sine and cosine values for a given angle. Keeps them in var int sinApprox var int cosApprox; variables.

func void SinCosApprox(var int angle)
Parameters
  • var int angle
    Angle in degrees