Trying to load a spritesheet in MicroPython

I’m trying to load a spritesheet in MicroPython like so:


x = 60
y = 60

my_sprites = Buffer(128, 128)
open(“invader.16bpp”, “rb”).readinto(my_sprites)
spritesheet(my_sprites)

def update(tick): **
** global x

** global y**
# pass
** if button(RIGHT):**
** x += 2**
** if button(LEFT):**
** x -= 2 **

def draw(tick):
** pen(0, 0, 0)**
** clear()**
** pen(0, 15, 0)**
** cursor(20, 20)**
** text(“Hello World”)**
** #flip()**


** pen(15, 0, 15)**
** fcircle(x, y, 5) **

start()pen(15, 0, 15)
** fcircle(x, y, 5) **

start()

and I’m getting this error:

Traceback (most recent call last):
** File “”, line 11, in **
OSError: [Errno 2] ENOENT

I have created a .16bpp file named and even tried one of the example .16bpp files, I still get the same error

Also I’m trying to display a sprite with:

sprite()

but I can’t find the syntax for what goes in the parenthesis in the documentation. (x, y, sprite number?) not sure?

Thanks,

Brian

code tags for this site are 3 ` at the top of your code and 3 more at the end.
Do that and it will retain the indents etc.
@Tonygo2 is likely the guy to help you sort that out. It’s way above my skill level that’s for sure.

Thanks! I figured that out after the fact. :(

ENOENT suggests it can’t find your file; are you sure you’ve copied it onto the device?

The sprite arguments, I probably need to know what you’re running on to guess on that :)

I’m using MicroPython on the PicoSystem.

Here’s the code displayed properly:

# Invader PicoSystem, MicroPython with PicoSystem API
# started xx/xx/xx
# Brian Kumanchik

# Note: save main.py to device to autoload

x = 55
y = 112
score = 999
lives = 3

my_sprites = Buffer(128, 128)
open("invader.16bpp", "rb").readinto(my_sprites)
spritesheet(my_sprites)
    

def update(tick):        
    global x
    global y
#     pass
    if button(RIGHT):
        x += 2
    if button(LEFT):
        x -= 2    

def draw(tick):
    global score
    pen(0, 0, 0)
    clear()
    pen(15, 15, 15)
    cursor(2, 2)
    text("SCORE: {}".format (score))
    cursor(75, 2)
    text("LIVES: {}".format (lives))   
    
    sprite(0, 20, 20, )
    #flip()
    
    pen(0, 15, 0)
    frect(x, y, 11, 4)    
    frect(x+5, y-1, 1, 1) 

start()

Scroll down to: Loading a spritesheet

OK, so I can successfully use the default/builtin spritesheet listed in the docs and display a sprite from it by using:

spritesheet()
sprite(0, 20, 20, 1, 1)

but I can’t seem to load my own or even one of the example spritesheets with:

my_sprites = Buffer(128, 128)
spritesheet(my_sprites)
open(“s4m_ur4i-pirate-characters.16bpp”, “rb”).readinto(my_sprites)

It fails on the open… line of code, I think it can’t find it, I have the .16bpp file in the same folder as my
.py file, do I need to place it on the PicoSystem some how, I tried but couldn’t seem to add it.

Any help would be appreciated, Thanks,

Brian

Ahh, yes you need to get the .16bpp file on the PicoSystem for it to be read - assuming you’re using Thonny to upload your code, you should be able to right click on your assets and ‘upload to /’ to send it to the device.

(I’ve only used the C SDK on the PicoSystem, which is a bit more of a faff because you have to convert your files into raw data to be compiled right into your code…!)

Thanks, I’ll try that.

I can’t figure this out, I’m using a Raspberry Pi, do I do this in Thonny? or in an explorer window? If it’s in Thonny, it’s not clear how to do this.

I’m working a little bit of what I’ve read, but… if your .16bpp file is in the same folder as your code, in Thonny it should be showing up in the ‘Files’ list on the left.

(there will now be a brief pause while I find Micropython and stick it on my Picosystem to find out what happens next…!)

Right; so, in the top pane of the ‘Files’ tab you (hopefully) have your invader.16bpp showing. Right click on that, select ‘Upload to /’ the same way you would transfer your main.py, and it should copy it over to your device.

That was the ticket, Thanks so much for your help!

Brian