Log In  


A cart that allows you to make sprites compatible with ESPR()

Cart #espr_maker-0 | 2021-07-01 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
5


So basically I made a function to add sprites beyond PICO-8's 128 by 128 sprite sheet. Feel free to use this function with credit.

function espr(data,x,y,w,h,flp_x,flp_y)
 --[[
 data is a list of all the
 pixels that make a sprite

 the sprites are 8 by 8 pixels

 this function can be used
 for easily adding new sprites
 into the game
 ]]

 list=split(tostr(data))

 w=w or 8
 h=h or (count(list)/8)

 x=x or 0
 y=y or 0

 local val=0

 local backup={}

 repeat
  add(backup,sget(val%w,val/w))
  val+=1
 until val==h*w
 for pnum,p in pairs(list) do
  pnum-=1
  if (pnum/w)<h then
   if p~=16 then sset(pnum%w,pnum/w,p) end
  end
 end
 sspr(0,0,w,h,x,y,w,h,flp_x,flp_y)
 for pnum,p in pairs(backup) do
  pnum-=1
  if pnum<=w*h then
   sset(pnum%w,pnum/w,p)
  end
 end
end

So, for example, if I do this:

espr("12,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,12",0,0,17,2)

It will output this:

5


Can you explain more how to use this? Where does the function "add" or "output" sprites?

If you’re open for some optimization ideas:

  • use hex notation for colours rather than decimal
  • pack two pixels in one byte

alright, so basically it's just spr() except, instead of there being a sprite number, it's just a string of values that make up the sprite. the values are separated by commas and go from left to right, and up to down.


Ah I see! You’re copying the value to spritesheet then restoring the original. Thanks for the reply.

One could make a small sprite editor that prints out data as hex numbers + a poke4 call (more efficient than sset), and the restore step could also be a simple 'reload'.


I made a cart that allows you to make Extra Sprites @merwok


I don’t get how that message replies or addresses the ideas in my last message.



[Please log in to post a comment]