If you are unfamiliar with other programming languages, or any sort of game making software, you are probably asking what importance a type of soda has in graphics design. But, I assure you that there is more than one type of sprite. One is a branded product by the Coca-Cola company; another is a type of fairy; the one we're dealing with is an image, of varying size, which a program can call to and display. Games usually consist of multiple sprites, one for each important type of item.
As a TI-BASIC coder, you'll be very limited in its use of sprites. Drawing sprites that require more than a few characters require assembly programs or applications installed in order to work properly. Those types of sprites will not be covered here. This tutorial will only address those very basic sprites that you can make in pure TI-BASIC. Before we progress any further, let me first let you know that using sprites in any fashion, but especially in TI-BASIC, consumes large amounts of time and memory. Optimization (which we'll look at later on) is crucial here.
The simplest way to draw a sprite is to draw it on the graph screen, store it to a picture (with StorePic
, and use RecallPic
whenever you need it. command. An issue with this method is that the designer must then makes sure he supplies the picture along with the program when he releases it, or else the calculator will throw an error. If the program requires several sprites, it becomes difficult to manage all the pictures. On top of this, there may not be enough free RAM; each picture is 767 bytes large, which is very significant in a calculator with only 24 KB of RAM.
The fact of the matter is that there really is no way around this fact: drawing sprites will be very demanding on speed and memory. But there are good methods, and one of them is used in the Snake game I have previously mentioned. In this game, the data where the walls will be is placed in a list, named L1. The data is entered in pairs of two, with an X-coordinate first followed by a Y-coordinate. Once this is done, the drawing routines begin. The routines move through the list, at increments of two. It will store the first in the pair to X, and the next to Y, and then turn on the point (X,Y). Then, it will jump to the next pair. This process will repeat until the list is finished.
A similar system can be used to display any kind of sprite, whether by line, by pixel, or by point. Once the image is displayed, the list used can be destroyed. A string can also hold a sprite. To display a border of X
's, you can use :Output(1,1,"XXXXXXXXXXXXXXXXX00000000000000XX00000000000000XX0000000000000000XX000000000000000XX000000000000000XX000000000000000XXXXXXXXXXXXXXXXX")
. Using this method, objects can be placed almost anywhere on the screen. But how to distinguish different objects and to respond accordingly? The next section details that.