Types
TSpriteInfo = tuple[frames: seq[TRect], w, h: uint16, cols, rows: int]
TAnimationAction = enum doNothing, setFirstFrame, deleteEntity
PSprite = ref TSprite
TSprite = object of TImageEx fSpritemap: PImage fSpriteInfo: TSpriteInfo fFrame: int play*, loop*: bool animFrames: seq[int] animIndex: int animRate*, animRateCounter: int animAction*: TAnimationAction
Procs
proc init(obj: PSprite; w: uint16 = 0; h: uint16 = 0; rows: int = 0; cols: int = 0; offsetX: int = 0; offsetY: int = 0)
proc free(obj: PSprite)
proc newSprite(filename: cstring; x: int = 0; y: int = 0; w: int = 0; h: int = 0; rows: int = 0; cols: int = 0; offsetX: int = 0; OffsetY: int = 0; smooth: cint = 1): PSprite
-
filename: image file to load from.
x, y: draw offset.
w, h: single frame size.
rows, cols: frame grid dimensions.
offsetX, offsetY: frame grid offset.
smooth: use smooth in transformations.
proc newSprite(surface: PSurface; x: int = 0; y: int = 0; w: int = 0; h: int = 0; rows: int = 0; cols: int = 0; offsetX: int = 0; OffsetY: int = 0; smooth: cint = 1): PSprite
proc updateSprite(obj: PSprite)
Methods
method maskedFill(obj: PSprite; color: TColor)
- Fill sprite map with given color but save alpha channel info.
method blitFrame(obj: PSprite; frame: int; dstSurface: PSurface; x: int16 = 0'i16; y: int16 = 0'i16)
- Blit single frame to the given dstSurface without changing current frame.
method blitFrame(obj: PSprite; frame: int; dstSurface: PSurface; x: int = 0; y: int = 0) {.inline.}
method frame(obj: PSprite): int {.inline.}
method frame=(obj: PSprite; value: int) {.inline.}
method frame=(obj: PSprite; value: varargs[int]) {.inline.}
- Usage: frame = [col, row]
method w(obj: PSprite): int {.inline.}
method h(obj: PSprite): int {.inline.}
method cols(obj: PSprite): int {.inline.}
method rows(obj: PSprite): int {.inline.}
method count(obj: PSprite): int {.inline.}
method setAnimation(obj: PSprite; frames: seq[int]; rate: int = 1; loop: bool = false; play: bool = true; action: TAnimationAction = doNothing)
-
frames: animation sequence frames.
rate: animation rate (change frame every rate ticks).
loop: true to looped animation.
play: true to play animation now.
action: action to do when animation is finished.
method setAnimation(obj: PSprite; first: int = 0; last: int = - 1; rate: int = 1; loop: bool = false; play: bool = true; action: TAnimationAction = doNothing)
-
first, last: animation frames range.
rate: animation rate (change frame every rate ticks).
loop: true to looped animation.
play: true to play animation now.
action: action to do when animation is finished.
method update(obj: PSprite) {.inline.}