Is anyone making carts that use 4x4 sprites? How do you manage clipping and printing them?

P#20194 2016-05-05 13:49 ( Edited 2016-05-06 11:39)

It's super easy when you use sspr()

sspr( x , y , w , h , dx , dy , [ dw , dh , a ] )
x -- x position to grab from spritesheet
y -- y position to grab from spritesheet
w -- width of grab
h -- height of grab
dx -- x position to draw onto game
dy -- y position to draw onto game
-- dw , dh , a are optional parameters
dw -- the width of sprite drawn
dh - the height of sprite drawn
a -- flip rotate stuff

 ```-- considering there's 4 4x4 sprites in one 8x8 sprite -- locations of sprite would be (0,0),(0,4),(4,0),(4,4) -- let's place them next to each other horizontally. sspr( 0 , 0 , 4 , 4 , 58 , 62 ) sspr( 0 , 4 , 4 , 4 , 62 , 62 ) sspr( 4 , 0 , 4 , 4 , 66 , 62 ) sspr( 4 , 4 , 4 , 4 , 70 , 62 ) ```
 ```-- a methos that uses way less bytes for i = 0 , 3 do sspr( (i/2)*4 , (i%2)*4 , (58+(i*4)) , 62 ) end ```

if your still having trouble, then i can make a quick cartridge for you that shows how its done <3

P#20198 2016-05-05 16:26 ( Edited 2016-05-05 20:26)
1

If I recall correctly, spr(Sprite number of upper left, x, y, tiles wide, tiles tall, flip x, flip y) can handle this as well.

So something like: spr(2,64,64,2,2) should do a 2x2 Sprite.

P#20207 2016-05-05 18:50 ( Edited 2016-05-05 22:50)
2

electricgryphon: The third and fourth parameters to spr() are in 8x8 tiles, so 2,2 gives you a 16x16 px sprite.

It seems you can use fractional numbers for these values though: e.g. 1.5, 1.5 will give you a 12x12px sprite. I dunno if this is intentional so it might go away in a future version, and since the sprites are numbered in rows of 8x8 tiles I'm not sure you can address the bottom half of a tile (maybe by using negative tile sizes??)

According to zep here, sspr() is twice as slow as spr().

P#20216 2016-05-06 03:51 ( Edited 2016-05-06 07:51)

You can also use clip() to restrain the drawing of your sprite to a 4x4 region. So you clip just before drawing the sprite with an offset to select witch quarter you want to draw. I just tested it, and it can be slightly faster than sspr but not much. Sspr seam to cost less when there is no resize of the sprite.

P#20220 2016-05-06 07:39 ( Edited 2016-05-06 11:39)