Sprite

One frame of a spritesheet at a time: a character that walks, a tank that drives and fires, a coin that spins. It plays the sheet’s sequences, and which frame or sequence it shows can be bound to a variable or set by any event. It is an ordinary image on the board, so it moves, turns and scales like one. Pro. Arduino, ESP-IDF and MicroPython exports.

Group: Ready-made · Default size: its sheet’s frame · Style parts: Main

Sprite settings for a widget named Tank: Spritesheet tank.png (48 frames), Resting frame 1, Plays by itself rest_up (1, 1 fps), Turns about Its middle, Rotation 0, Scale 256.
Its settings.
SettingDefaultWhat it does
SpritesheetnoneThe sheet it shows a frame of. Make one on the Assets tab: pick an image and switch on Spritesheet. The widget takes the sheet’s frame size.
Resting frame1The frame it shows while nothing plays, and the one the canvas draws. Counted from 1.
Plays by itselfnoneA sequence of the sheet it starts as its screen is made.
Turns about, Pivot X, Pivot YIts middleOr a point of its own, in the frame.
Rotation0In degrees, to a tenth.
Scale256256 is the frame’s own size, 512 twice it.
AntialiasonSmooths a turned or scaled frame. Off keeps pixel art sharp.

What can drive it, on the Data tab. Each acts when the value it is given changes, not on every pass, so a frame number that stays the same never stops a sequence that is playing.

Bound toWhat it does
Frame shown (from 1)Shows that frame, and stops what plays: a picture with as many states as the sheet has frames.
Frame shown, by its nameA text variable naming a frame. A name the sheet has not got leaves it as it is.
Sequence playing, by its nameA text variable naming a sequence: it plays it. Empty text, or a name it has not got, pauses it.
Sequence playing, by its numberThe same by number, from 1, so a formula can choose it; 0 pauses it.
PlayingOn carries on with the sequence it has; off pauses it.
Rotation, X, Y, Width, Height, Hidden, OpacityAs on any widget: a value that turns it or moves it.

From an event. The Play frames action takes a Sprite as well as an Animation, with a Sequence to play; left at the one it has, Plays carries on and Starts again goes back to its first frame. Any event can do it: a key’s Pressed plays walk_left while a Set variable beside it moves the Sprite’s bound X. Its own event is Sequence finished, sent when a sequence that plays once reaches its last frame.

What it costs. The sheet is stored once in the firmware whatever the number of Sprites on it, and a Sprite adds a timer that is paused whenever nothing plays. See Spritesheets: on the board. Preview plays it as the board does, except that Sequence finished is not sent there. Compiled for LVGL 8 and 9, and run on the real MicroPython binding; not yet run on a board.

Example: a battle tank

  1. Make tank.png a spritesheet: eight rows of six 40 × 40 frames, one row for each way the tank faces.
  2. Drag a Sprite into a panel and choose tank.png. It takes the frame’s size, 40 × 40.
  3. Bind its X and Y to the variables a Joystick moves, and its Sequence playing, by its number to one an automation works out from the stick’s angle.
  4. Press Preview and push the stick: it drives the way you push, its tracks rolling. The whole example.
A 320 x 480 screen titled BATTLE TANK: a sand-coloured pen with the tank in the middle facing up, a joystick bottom left and a red FIRE button bottom right.
On the canvas.