Frequently Asked Question

How do I create sprite graphics?
Terakhir diperbaharui 8 hari yang lalu

Sprite Programming on the Commodore 64

The VIC-II chip provides 8 hardware sprites - movable graphics objects perfect for games!

Sprite Basics

  • 8 sprites numbered 0-7
  • Each sprite is 24x21 pixels
  • Each sprite uses 63 bytes of data
  • Can be single color or multicolor

Sprite Design Grid

Design your sprite on a 24x21 grid. Each row becomes 3 bytes (24 bits = 3 x 8 bits):

Byte 1Byte 2Byte 3B1B2B3
1...........X............0160
2..........XXX...........0560
3.........XXXXX..........01240
4........XXXXXXX.........02540
5.......XXXXXXXXX........12550
6XXXXXXXXXXXXXXXXXXXXXXXX255255255
7.......XXXXXXXXX........12550
8........XXXXXXX.........02540
9.........XXXXX..........01240
10..........XXX...........0560
11...........X............0160

This shows a simple arrow/ship sprite. The X marks are "on" pixels (1), dots are "off" (0). Convert each row of 8 pixels to a byte value (0-255).

BASIC Program: Arrow Sprite

10 REM *** ARROW SPRITE ***
20 FOR I = 832 TO 832+62: POKE I,0: NEXT
30 FOR I = 0 TO 32: READ D: POKE 832+I, D: NEXT
40 DATA 0,16,0
50 DATA 0,56,0
60 DATA 0,124,0
70 DATA 0,254,0
80 DATA 1,255,0
90 DATA 255,255,255
100 DATA 1,255,0
110 DATA 0,254,0
120 DATA 0,124,0
130 DATA 0,56,0
140 DATA 0,16,0
150 POKE 2040, 13       : REM SPRITE 0 DATA BLOCK
160 POKE 53287, 1       : REM SPRITE 0 = WHITE
170 POKE 53248, 170     : REM X POSITION
180 POKE 53249, 140     : REM Y POSITION
190 POKE 53269, 1       : REM ENABLE SPRITE 0
200 REM *** MOVE WITH JOYSTICK ***
210 J = PEEK(56320)
220 IF (J AND 1) = 0 THEN POKE 53249, PEEK(53249)-2
230 IF (J AND 2) = 0 THEN POKE 53249, PEEK(53249)+2
240 IF (J AND 4) = 0 THEN POKE 53248, PEEK(53248)-2
250 IF (J AND 8) = 0 THEN POKE 53248, PEEK(53248)+2
260 GOTO 210

Sprite Registers Quick Reference

Address Purpose
53248-53263Sprite X/Y positions (pairs)
53269Sprite enable register (bits 0-7 = sprites 0-7)
53271Expand Y (double height)
53277Expand X (double width)
53276Multicolor mode enable
53287-53294Sprite colors 0-7
2040-2047Sprite data pointers (block number)

Sprite Collision Detection

10 REM CHECK SPRITE-SPRITE COLLISION
20 C = PEEK(53278)
30 IF C > 0 THEN PRINT "COLLISION!"
40 REM CHECK SPRITE-BACKGROUND COLLISION
50 B = PEEK(53279)
60 IF B > 0 THEN PRINT "HIT BACKGROUND!"

Multicolor Sprites

Multicolor sprites use 4 colors but have half horizontal resolution:

  • 00: Transparent
  • 01: Sprite multicolor 0 (53285)
  • 10: Sprite own color (53287+n)
  • 11: Sprite multicolor 1 (53286)
"Master sprite programming and you can create games that rival the arcade. The VIC-II chip makes it possible!" - COMPUTE!'s Gazette
This website relies on temporary cookies to function, but no personal data is ever stored in the cookies.
OK

Menunggu ...