sprite

Draw sprites stored in AppVars, separately from your program. This keeps large images out of the program and works on archived AppVars. This library needs the CE: the CE assembly target or a Flash App.

For sprites built into your program, on either assembly target, use graphics.sprite(). A PNG asset with storage = "program" does that for you; see Projects.

Build a sprite

Declare the image as an asset. Every build then writes bin/HERO.8xv, which you send to the calculator with the program:

[[tool.tipy.assets]]
source = "assets/hero.png"
name = "HERO"

Draw it

from ti84 import sprite

hero = sprite.load("HERO")
if hero == 0:
    print("Send HERO.8xv first")
    exit()
sprite.draw(hero, x, y)

load() returns the sprite’s address as an integer, or 0 if the AppVar is missing. Drawing a missing sprite does nothing.

Transparent pixels in the image stay transparent. Color 0 means transparent, so the converter stores opaque black as the nearest visible color.

Packs

A pack puts several sprites in one AppVar, so there is one file to send. Give the sprites the same pack in their assets, and load each by its index. The build writes the indexes to sprites.py:

from ti84 import sprite
from sprites import FLOWER, GRASS

grass = sprite.load("TILES", GRASS)
flower = sprite.load("TILES", FLOWER)

An index past the end of the pack gives 0. A single-sprite AppVar is a pack of one, so sprite.load("HERO") and sprite.load("HERO", 0) are the same.

Not implemented

Scaled and rotated drawing and per-pixel access are not implemented. Calling them is a compile error.

Methods

load(name, index=0) → int

Find a sprite AppVar built by [[tool.tipy.assets]], or sprite number index of a pack; 0 if missing.

Targets:

CE, Flash App

Note:

AppVar sprites need the CE target; use graphics.sprite.

hero = sprite.load('HERO')
draw(sprite, x, y)

Draw a loaded sprite, clipped, with color 0 transparent.

Targets:

CE, Flash App

Note:

AppVar sprites need the CE target; use graphics.sprite.

sprite.draw(hero, x, y)
width(sprite) → int

A loaded sprite’s width.

Targets:

CE, Flash App

Note:

AppVar sprites need the CE target.

z = sprite.width(hero)
height(sprite) → int

A loaded sprite’s height.

Targets:

CE, Flash App

Note:

AppVar sprites need the CE target.

z = sprite.height(hero)