Skip to content

BASIC Sprite Tutorial

Sean P. Harrington edited this page Jun 9, 2024 · 12 revisions

Creating and animating a Sprite in plusBASIC

Designing The Sprite

This starfighter Sprite uses the default text screen palette:

  • 1 = Red
  • 4 = Blue
  • 8 = Light Gray
  • F = Dark Gray
  • . = transparent)
      ...FF...
      ..F44F..
      ..F44F..
      ..F44F..
      .F4444F.
      .F4444F.
      F.4444.F
      F444444F
  ...F48844884F...
  ..F4888448884F..
  .F488884488884F.
  F44444444444444F
  F44444444444444F
  F44FFFF44FFFF44F
  FFF.11.FF.11.FFF
  ...1111..1111...

It is made up of three 8x8 Tiles:

  ...FF...  ...F4884  4884F...
  ..F44F..  ..F48884  48884F..
  ..F44F..  .F488884  488884F.
  ..F44F..  F4444444  4444444F
  .F4444F.  F4444444  4444444F
  .F4444F.  F44FFFF4  4FFFF44F
  F.4444.F  FFF.11.F  F.11.FFF
  F444444F  ...1111.  .1111...

Note that the third Tile is the second one flipped horizontally.

Writing the program

Setup

First, all existing Sprite definitions are cleared.

100 REM Sprite Demo
110 SET SPRITE * CLEAR

Then text screen 1 is selected, Sprite display is enabled, and the text screen is cleared.

115 SCREEN 1,0,1:CLS 6,0

Defining the Tiles

120 T0$=$"...FF..."
121 T1$=$"..F44F.."
122 T2$=$"..F44F.."
123 T3$=$"..F44F.."
124 T4$=$".F4444F."
125 T5$=$".F4444F."
126 T6$=$"F.4444.F"
127 T7$=$"F444444F"
128 SET TILE 0 TO T0$+T1$+T2$+T3$+T4$+T5$+T6$+T7$

130 T0$=$"...F4884"
131 T1$=$"..F48888"
132 T2$=$".F488888"
133 T3$=$"F4444444"
134 T4$=$"F4444444"
135 T5$=$"F44FFFF4"
136 T6$=$"FFF.11.F"
137 T7$=$"00011110"
138 SET TILE 1 TO T0$+T1$+T2$+T3$+T4$+T5$+T6$+T7$

Defining and creating the Sprite

The Sprite is made up of three Spritles (sprite tiles):

  • 0 at offset 4,0
  • 1 at offset 0,8
  • 2 at offset 8,8
140 DEF SPRITE S$ = 0,4,0 ; 1,0,8 ; 2,8,8

The Spritles will use Tiles 0, 1, and 1, respectively.

150 DEF TILELIST T$ = 0,1,1

The Spritles all use the default Attributes, except the third one, which is flipped horizontally.

160 DEF ATTRLIST A$ = 0,0,2

The Sprite is then created.

170 SET SPRITE S$ TILE T$ ATTR A$

The Sprite is now positioned and displayed at the center bottom of the screen.

180 SET SPRITE S$ POS 152,180 ON

Moving the Sprite

The following code creates a loop that moves the Sprite up the screen:

200 REM Move the Sprite
210 FOR I=180 TO 5 STEP -1
220 SET SPRITE S$ POS 152,I
230 FOR D=1 TO 10:NEXT
240 NEXT
Clone this wiki locally