Skip to content

rq.Sprite ​

since 1.9.0

A mod sprite among the game's own, made by rq.sprite.new.

The methods that return the sprite can be chained.

Functions ​

NameSummary
rq.Sprite:setChanges only the options given.
rq.Sprite:getReturns the sprite's options now.
rq.Sprite:removeRemoves the sprite.
rq.Sprite:aliveReturns whether the sprite is still there.
rq.Sprite:playPlays the sprite's GIF or Flash file.
rq.Sprite:stopHolds the GIF or the Flash file on the frame it is on.
rq.Sprite:frameReturns the frame shown, or shows one and stops.
rq.Sprite:playingReturns whether the sprite's GIF or Flash file is playing.
rq.Sprite:toMoves the sprite from the values it has now to new ones, over time.
rq.Sprite:movingReturns whether a motion is waiting or moving.
rq.Sprite:haltStops the motion where it is, without its on_end.

rq.Sprite:set ​

lua
rq.Sprite:set(opts) -> rq.Sprite

since 1.9.0

Changes only the options given.

Raises an error for a bad option, or after the sprite was removed.

ParameterTypeDescription
optsrq.SpriteOptsThe options to change.
ReturnsTypeDescription
selfrq.SpriteThe sprite.

rq.Sprite:get ​

lua
rq.Sprite:get() -> table

since 1.9.0 changed 1.10.0 changed 1.11.0 changed 2.63.0

Returns the sprite's options now.

Besides the options it has id, mod, w and h before the scale (the content's own size when not set), origin as {x, y}, screen (with keep = "screen"), in_scene (shown and drawn), clock and moving. A GIF sprite adds gif, frame, frames, gif_ms (one time through), fps and playing; a Flash sprite flash, frame, frames, fps, playing and sound. An attached sprite adds attach and drawn = {x, y, z}, where it is drawn now.

Raises an error after the sprite was removed.

ReturnsTypeDescription
optstableA copy of the options.

Changed in 1.10.0: Added the GIF and motion fields.

Changed in 1.11.0: Added attach and drawn.

Changed in 2.63.0: Added the Flash fields.

rq.Sprite:remove ​

lua
rq.Sprite:remove()

since 1.9.0

Removes the sprite.

set and get raise an error after that.

rq.Sprite:alive ​

lua
rq.Sprite:alive() -> boolean

since 1.9.0

Returns whether the sprite is still there.

ReturnsTypeDescription
alivebooleanfalse once it was removed: by the mod, a load, the title or keep.

rq.Sprite:play ​

lua
rq.Sprite:play(opts) -> rq.Sprite

since 1.10.0 changed 2.63.0

Plays the sprite's GIF or Flash file.

A Flash file goes one frame on each 1/30 s, its tags walked in turn as the game walks them: a gotoFrame in it jumps, a stop ends the play as its last frame does, and each sound starts at its frame. Going back to from walks its frames again from the start, without their sounds.

Raises an error for a sprite with no GIF or Flash file, or a range outside its frames.

ParameterTypeDescription
opts (optional){from?: integer, to?: integer, loop?: boolean, on_end?: fun(s: rq.Sprite )}from (default 1) to to (default the last frame), over again unless loop = false. on_end runs when a play without loop reaches its last frame.
ReturnsTypeDescription
selfrq.SpriteThe sprite.

Changed in 2.63.0: A Flash file.

rq.Sprite:stop ​

lua
rq.Sprite:stop() -> rq.Sprite

since 1.10.0 changed 2.63.0

Holds the GIF or the Flash file on the frame it is on.

ReturnsTypeDescription
selfrq.SpriteThe sprite.

Changed in 2.63.0: A Flash file.

rq.Sprite:frame ​

lua
rq.Sprite:frame(n) -> integer|rq.Sprite, integer?

since 1.10.0 changed 2.63.0

Returns the frame shown, or shows one and stops.

A Flash file walks its tags to frame n, so a jump in them may show another; the frame read after says which.

Raises an error for a frame outside the GIF or the Flash file.

ParameterTypeDescription
n (optional)integerThe frame to show, from 1; leave it out to read.
ReturnsTypeDescription
frameinteger| rq.SpriteWithout n: the frame shown. With n: the sprite.
countinteger?Without n: how many frames there are.

Changed in 2.63.0: A Flash file.

rq.Sprite:playing ​

lua
rq.Sprite:playing() -> boolean

since 1.10.0 changed 2.63.0

Returns whether the sprite's GIF or Flash file is playing.

ReturnsTypeDescription
playingbooleantrue while it plays.

Changed in 2.63.0: A Flash file.

rq.Sprite:to ​

lua
rq.Sprite:to(opts) -> rq.Sprite

since 1.10.0

Moves the sprite from the values it has now to new ones, over time.

A new to takes the place of the one moving, from where it got to, and the old on_end does not run. Sprite:set of a value takes that value out of the motion, and the rest goes on. Removing the sprite ends it too.

Raises an error for a negative ms or delay, an unknown ease, or an on_end that is not a function.

lua
rq.sprite.new({ fill = { 255, 255, 255 }, w = 1024, h = 768, z = "top" })
  :to({ alpha = 0, ms = 300, on_end = function(s) s:remove() end })  -- a white flash
ParameterTypeDescription
optsrq.SpriteMotionThe values and the timing.
ReturnsTypeDescription
selfrq.SpriteThe sprite.

rq.Sprite:moving ​

lua
rq.Sprite:moving() -> boolean

since 1.10.0

Returns whether a motion is waiting or moving.

ReturnsTypeDescription
movingbooleantrue until the motion ends.

rq.Sprite:halt ​

lua
rq.Sprite:halt() -> rq.Sprite

since 1.10.0

Stops the motion where it is, without its on_end.

ReturnsTypeDescription
selfrq.SpriteThe sprite.

Used by ​

rq.PlayFlashOpts, rq.Sprite:frame, rq.Sprite:halt, rq.Sprite:play, rq.Sprite:set, rq.Sprite:stop, rq.Sprite:to, rq.SpriteAttach, rq.SpriteMotion, rq.image.play_flash, rq.sprite.list, rq.sprite.new