| NedoPC Project | NedoPC Forum | NedoPC Group |

Sprinter SDK Documentation


[PREV] : LESSON 2 : [NEXT]

In this lesson we'll see how to create sprite files. When the editor saves HELLO.RW1, it also creates a few auxiliary files. One of them is named HELLOS.SPR. To open it, run the SDK Editor and click on File/Open... ( or just hit key F3 ), select "All Files ( *.* )" under the 'Files of type:' box, select HELLOS.SPR and click 'Open'. You'll see just one line:
 ;8x8-2/16 
Currently, only 8x8 pixel sprites are supported, consisting of 2 colors from a palette of 16. If the screen is set to 320x256, then there is the possibility of drawing 40x32 pixel sprites. Besides, a 256 color background can be used ( more on that later lessons ). So, what is the sprite format in the file? The sprite is defined by typing the hexadecimal ( hex for short ) numbers of every sprite row in the line as follows ( example taken from an existing SPR file ) :
 NAME DB #00,#11,#AA,#55,#00,#00,#00,#00,#F4 ;x 
We have 8 bytes of sprite data, then a byte for the color. The sprite data bytes ( one bite per sprite row in this case ) have a SET ( 1 ) bit to represent the FOREGROUND color, and a RESET ( 0 ) bit to represent the BACKGROUND color. The color byte is divided in two parts, the upper 4 bits ( 7 - 4 ) specify the BACKGROUND color, and the lower 4 bits ( 3 - 0 ) specify the FOREGROUND color. Possible colors are ( FOREGROUND is INK, BACKGROUND is PAPER ):
 0 - Black      8 - Dark Gray 
 1 - Blue       9 - Light Blue 
 2 - Green      A - Light Green 
 3 - Cyan       B - Light Cyan 
 4 - Red        C - Light Red 
 5 - Magenta    D - Light Magenta 
 6 - Brown      E - Yellow 
 7 - Light Gray F - White 
After the last data byte we could add a semicolon ( ; ) followed by a one-character sprite identifier ( not used in the present SDK ). Let's create a funny face as a working example. Let's make this sprite:
 ######## -> #FF 
 #      # -> #81 
 # #  # # -> #A5 
 #      # -> #81 
 #      # -> #81 
 #  ##### -> #9F 
 #      # -> #81 
 ######## -> #FF 
We'll also draw the face red ( FOREGROUND ) on black ( BACKGROUND ), so the color byte will be:
 BACK  FORE 
 PAPER INK 
 Red   Black 
 #4    #0    -> #40 
Finally, we can assemble the 9 bytes ( data and color ):
 ;8x8-2/16 
 MYSPR DB #FF,#81,#A5,#81,#81,#9F,#81,#FF,#40 ;@ 
We are keeping the format ( ;8x8-2/16 ) line for reference. So, open the file HELLOS.SPR and edit the lines there. Save the file and open our HELLO.RW1 project again: We need to add the sprite definition and we will also add the commands to show our sprite. Edit the program so it looks as follows:
 robot "Hello" 
 author "NedoPC" 
 +hellos.rwi 
 main() 
 { 
  say "HELLO, WORLD !" 
 } 
Save, compile and run the program. In RW1, the RWI file is what the compiler needs to know that there is some file or files to include. But... The sprite is not on screen yet! Ok, open again the project and edit it so it looks like:
 robot "Hello" 
 author "NedoPC" 
 +hellos.rwi 
 main() 
 { 
  say "HELLO, WORLD !" 
  select 0 0 // choose cell for drawing 
  set @MYSPR // draw our sprite MYSPR 
 } 
The SELECT command sets where in the screen our sprite will be. The syntax is:
 SELECT {column} {row}
And the SET command makes the SELECTed cell display the sprite. The syntax is:
 SET @{spritename}
The sprite name is the text string before the "DB" in the HELLOS.SPR file we created.

Ok, compile and run the robot (program). If all was correct, we will be able to see the face in the upper-left screen corner. But the screen is BLACK, so we cannot see the sprite's contour. Let's change the sprite's colors. Exit the emulator and get back to the editor. Open the sprite file ( you REMEMBER how to do this, don't you? ). Make it look as follows:

 ;8x8-2/16 
 MYSPR DB #FF,#81,#A5,#81,#81,#9F,#81,#FF,#4F ;@ 
Save the file and open the program. Compile and run it. Now we have a bright-white contour and the red face. Easy, isn't it? That's all for this lesson. You can now go on and create your own sprite art.

[ ONLINE HELP ]


Rambler's Top100
^ Go Up
© 2002-2008 NedoPC.org