Sprites On The NXT
Blueprint on LaunchpadScratch makes heavy use of Sprites — characters on the screen that can move about, turn around, 'say' things (using speech bubbles), change colour, start sounds, detect their environment, and so on.
Enchanting would like to use simplified sprites on the NXT screen.
- the sprites are limited to four colours — black, white, transparent, and, just possibly, inverted.
- the sprites will not be able to shrink or grow.
- the sprites will only certainly support one rotation mode, with two
other modes being later possibilities.
- no rotation
- object faces left or right
- object rotates in 90 degree increments.
- (note that sprites can face in any direction, even if the rotation mode doesn't rotate the graphic.)
- the sprites will be able to draw lines and 'stamp' themselves on the screen.
- sprites can 'say' things. I don't think we'll put speech or thought bubbles up. It may be nice to be able to change the font.
Sprites can move to specific coordinates. It may make sense to have four quadrants (as Scratch does), and put (0, 0) at the center of the screen. (Or as close to the center as possible with an even number of pixels.)
To implement this, we need, on the Squeak side of things:
- to change the drawing editor from supporting colours and transparency to simply supporting black and white and transparency (and inversion?)
- to make the maximum sprite size smaller
- to make the stage size match the NXT's screen size
- to export a representation for LeJOS — quite possibly by emitting an array of constant values in the code, or, possibly, by saving a bitmapped image. See the NXTImageConverter project for ideas on how to do this.
And, on the LeJOS side of things:
- We need to draw the screen as follows, perhaps using dirty rectangle
optimizations:
- In a double-buffer, draw the current background, including any lines and stamps on it
- Go through all the sprites (in reverse Z-order?) and draw them, and any text associated with them
- Draw any variables, reporters, or sliders that show up on the screen.
We need to be able to draw sprites that have transparency (and inversion?). We also need a buffer for the current background image so that it can accumulate lines and stamps.