PICO-8 Wiki
Register
Advertisement
sspr( sx, sy, sw, sh, dx, dy, [dw,] [dh,] [flip_x,] [flip_y] )
Draws a rectangle of pixels from the sprite sheet, optionally stretching the image to fit a rectangle on the screen.
sx
The x coordinate of the upper left corner of the rectangle in the sprite sheet.

sy
The y coordinate of the upper left corner of the rectangle in the sprite sheet.

sw
The width of the rectangle in the sprite sheet, as a number of pixels.

sh
The height of the rectangle in the sprite sheet, as a number of pixels.

dx
The x coordinate of the upper left corner of the rectangle area of the screen.

dy
The y coordinate of the upper left corner of the rectangle area of the screen.

dw
The width of the rectangle area of the screen. The default is to match the image width (sw).

dh
The height of the rectangle area of the screen. The default is to match the image height (sh).

flip_x
If true, the image is drawn inverted left to right. The default is false.

flip_y
If true, the image is drawn inverted top to bottom. The default is false.

This operation is affected by the draw state.


Unlike spr(), this function uses pixel locations on the sprite sheet instead of sprite numbers. The sprite sheet is treated as an image 128 pixels wide and 128 pixels high, where (0, 0) is the upper left corner.

If you know the sprite number sp, you can get its coordinates in the sprite sheet (sx, sy) using this formula:

sx, sy = (sp % 16) * 8, (sp \ 16) * 8


This is because the sprite sheet has 16 sprites per row and each sprite is 8x8.

Examples[]

-- draw the 8 x 8 image from (8, 0) at screen location (60, 60)
sspr(8, 0, 8, 8, 60, 60)

-- draw the same image but stretched to 12 x 20 at screen location (44, 48)
sspr(8, 0, 8, 8, 44, 48, 12, 20)

-- draw it again, flipped horizontally, at (72, 48)
sspr(8, 0, 8, 8, 72, 48, 12, 20, true, false)

This example appears to distort the original image differently based on whether the image is flipped. Notice that the stretched image must still use the 128 x 128 resolution of PICO-8. To stretch from 8 pixels to 12, sspr() doubles the width of every other column. Because of how this sprite is drawn, the flipped version puts the features of the image (hair, face, arms) on different columns, so different features get double-wide in the flipped version.

A demonstration of sspr.
The sprite sheet used in this example.

See also[]

Advertisement