You may yourself have experimented with the IMPORT ability for Pico-8 to import sprite sheets. However if you tried it inside your own code, it doesn't work, that is until your program ends.
So how can this be accomplished ?
Well first off understand the method I found only works for the IDE, that is, this will not work Online, offline Java or exported to an EXE/Mac. It only works in the IDE.
Here is the code:
-- the power of import -- written by dw817 (11-24-19) import "one.png" if sget(3,3)==0 then run"" end cls() ?[[ there are no sprites in this program. what you see was loaded from an external file. ]] for i=0,15 do spr(0,i*8,60) end repeat flip() until forever |
Save that as IMP.p8 if you like.
What's happening here ? It's pretty tricky actually. The first thing I do is import a .PNG file sized 8x8-pixels. Naturally it doesn't appear so the next line is TRUE, that is, the pixel at coordinates 3x3 on the sprite sheet is black. So then I RUN the program AGAIN.
At this point the IMPORT is added so the next statement is false. Then just run the rest of the code to show the sprite got loaded.
Here is a sprite to work with. Save it as ONE.PNG. Have it in the same directory as your IMP.p8 file.
[8x8] | |
Run the code and you will see it will import it after auto-executing it a 2nd time.
If you're content with this then you can indeed IMPORT any number of sprites, 256-at a pop per imported 128x128 pixels .png file if you like.
Perhaps in future Pico-8 you can indeed IMPORT or EXPORT any sprite sheet at any time without such methods, but this is not the case currently.
HOPE THIS HELPS !
[Please log in to post a comment]