Doc ver. 0.02
NxtOSEK sprite allows a user to play 1-bit animations on the Nxt’s LCD screen. The sprite system requires no memory allocation and provides some common effects such as screen clipping, vertical and horizontal flipping and of course, animation.
How does it work?
Sprite data is created using some common tools (see below) and saved as binary data. A special rule added to a project’s make file imports this data as static binary data and links it to a project’s executable data. There after, a sprite class containing data to manipulate and draw frames of the sprite is created and manages the raw binary data. Once this step is complete, animation is a matter of registering the sprite and allowing the system to handle animation and drawing.
Creating a compatible sprite
You’ll need the following software tools:
SeveuP v1.20 http://www.speccy.org/metalbrain/
A hex editor. I use Hackman http://www.technologismiki.com/prod.php?id=31
There are few remaining 1-bit graphics editors and SeveuP may be the best. It was written for editing graphics for the Timex Spectrum (and other) 8-bit computers. Since it accommodates 1-bit graphics, it’s wonderfully suited for our purposes.
Once we’ve created and collected all of our sprite data in to a file using SeveuP, we’ll need to add a small header to that file which describes the file’s data. This allows us to import the data into our software sprites without explicitly telling the sprite about the binary data in code. This makes code cleaner and nicely separates data and functionality.
Either SeveuP or NXTSprite Studio may include functionality in the future for adding this header, but for now adding it with a hex editor is necessary.
Open SeveuP and create a new file:
Change the size to 8 x 8 pixels. The size of a sprite’s width and height is subject to two restrictions in the current version of the software. Width and height must be multiple of 8 pixels and either dimension should be smaller the 256 pixels.
SevenuP has several export options. We’ll need to tell it to export each frame’s raw pixel data into a file that we append to for each subsequent animation frame.
Left click-drag to draw the following image:
Some earlier B&W computers used inverted graphics data by default. SevenuP exports each of these frames as inverted images. If we displayed this data in its current state, black pixels would show up white and vise versa. To correct this, click the INV button. From now until SevenuP is closed, all of the images will export correctly.
Now let’s export this image as the first of our sprite frames.
Add to this same image another square of pixels.
Select export again and this time select the “square.bin” file you created when exporting in the following step. SevenuP will append this image as new data to the first file.
Do these same steps twice more, adding one more ring, exporting, add the final four inner pixels and export one last time.
Manipulating the hex data
Open Hackman Hex Editor. Open the “square.bin” file we just created. We can change some of the hex editor’s settings to better visualize our data. Set the left and right panels to hex and binary data.
Set the column width to eight
You should see an exact copy of the follow data. This is your sprite. If you look closely enough, you’ll see the data we entered in SevenuP.
Now we’ll add the header. Left click on the first “FF” and select “Insert” from the shell menu. Do this two more times. The data should now look like this:
Drag-select the first byte of data.
Modify the data.
Select the following options.
This tells the sprite system that the width of our sprite is 8 pixels. Now modify the next two bytes in the same manner, storing 8 and then 4. This tells the sprite system that the height is also 8 pixels and that there are 4 frames of animation.
Now save the modified data as “square.spr.” You can now use this 4-frame sprite with the sprite system. Try placing it in the demo directory and use the existing sprites as an example.