Replies: 4 comments 1 reply
-
Sprites can also be loaded in "PicoVision Sprite" or ".pvs" format, there's a tool for conversion here - https://github.com/MichaelBell/picovision/blob/feature/sprite-loading/scripts/sprite_convert.py and the format is currently:
|
Beta Was this translation helpful? Give feedback.
-
I've come up with a somewhat janky code snippet to deal with sprite limitations- class SpriteList:
def __init__(self):
self.items = []
def add(self, image, x, y, force=False):
if len(self.items) == 32:
if force:
self.items.pop(0)
else:
return
self.items.append((image, x, y))
def clear(self):
self.items = []
def display(self):
for i in range(32):
try:
image, x, y = self.items[i]
display.display_sprite(i, image, x, y)
except:
display.clear_sprite(i)
spritelist = SpriteList() It's a little rough and ready, but is based around the idea that we don't really care about sprite slots and that should just be handled as an implementation detail. Currently on every frame of my sprite-powered Floppy Birb I'm calling: spritelist.clear() To clear the sprite list, then adding pipe sprites: spritelist.add(SPRITE_PIPE, pipe_x, GAME_TOP + top_pipe_height - n - CAP_HEIGHT)
spritelist.add(SPRITE_PIPE_CAP, pipe_x - 3, top_pipe_end - CAP_HEIGHT)
spritelist.add(SPRITE_PIPE, pipe_x, bottom_pipe_start + CAP_HEIGHT) And player/goal sprites: spritelist.add(SPRITE_GOAL, int(goal_x), goal_y, force=True)
spritelist.add(BIRBS[int(current_x / 10) % 3], int(WIDTH / 6), int(birb_y), force=True) With This works surprisingly well and some form of it could maybe be a standard lib for PicoVision MicroPython. |
Beta Was this translation helpful? Give feedback.
-
One thing the Amiga was able to do in hardware ( Denise IC ) was change a palette colour every scan line. |
Beta Was this translation helpful? Give feedback.
-
Note that some of the info here is getting out of date, take a look at https://github.com/pimoroni/picovision/blob/patch-picographics-docs/docs/hardware.md for more info. |
Beta Was this translation helpful? Give feedback.
-
The "GPU" - RP2040 - offers "hardware" accelerated sprites and scanline scrolling that can be useful when trying to push a lot of pixels quickly.
Sprites
First, some terms-
An index must be specified when loading an image, and can later be used to refer to that specific image and assign it to a sprite. It's a good idea to use a variable to keep track of these:
Note: the quirk of loading the sprite twice in a loop is because we must swap the hardware PSRAM buffers and load the image data into each. This might be swept into PicoGraphics in future.
A sprite slot can display a specific sprite - referenced by its index - at a given X and Y position. Once displayed the sprite will continue to display at its given X and Y coordinates without any intervention from your code.
The
display_sprite
function serves both to display a sprite and to update its location or image:The current maximim size for a sprite is 2k, which corresponds to a 32x32 pixel image, however there are no restrictions on width/height so non-square images exceeding one of these dimensions and making up for it in the other is fine- so long as they don't exceed 2k (2 bytes per pixel).
Scanlines
You can configure the "GPU" to scroll up to three groups of scanlines at indexes 1, 2 and 3. The following code cuts a 240 pixel tall frame into three horizontal slices:
Once the scroll groups have been configured, you can ask the "GPU" to offset them like so:
The last argument is the scroll group (it can be either 1, 2 or 3).
Frame vs Display
The
PicoGraphics
constructor can optionally take a frame Width and Height which specifies a larger drawing area that you can pan around with scroll offsets. This is useful to mask slow drawing of new elements, or to contain additional horizontal data that the scanline scrolling could bring into view.Beta Was this translation helpful? Give feedback.
All reactions