pico8 draw sprite

To draw a sprite in Lua using PICO-8, follow these steps:

  1. Use the spr() function to draw the sprite. The spr() function takes three parameters: the sprite number, the x-coordinate, and the y-coordinate. For example, to draw sprite number 1 at position (10, 20), you would use spr(1, 10, 20).

  2. The sprite number corresponds to the sprite sheet index. In PICO-8, sprites are stored in a sprite sheet, which is a grid of 8x8 pixel sprites. Each sprite is assigned a unique number starting from 0. If you're using the built-in PICO-8 sprites, you can refer to the PICO-8 sprite sheet documentation to find the sprite numbers for the desired sprite.

  3. The x-coordinate and y-coordinate specify the position where the sprite will be drawn on the screen. The origin (0, 0) is the top-left corner of the screen. The x-coordinate increases from left to right, and the y-coordinate increases from top to bottom.

  4. You can also specify an optional fourth parameter to control the horizontal flip of the sprite. If you want to flip the sprite horizontally, you can pass 1 as the fourth parameter. For example, to draw sprite number 1 flipped horizontally at position (10, 20), you would use spr(1, 10, 20, 1).

  5. Additionally, you can specify an optional fifth parameter to control the vertical flip of the sprite. If you want to flip the sprite vertically, you can pass 2 as the fifth parameter. For example, to draw sprite number 1 flipped vertically at position (10, 20), you would use spr(1, 10, 20, 0, 2).

That's it! By following these steps, you can draw sprites in Lua using PICO-8.