PICO-8 Wiki
No edit summary
Tags: Visual edit apiedit
m (→‎See also: formatting)
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
  +
{{ApiReference
'''spr(n, x, y, [w, h], [flip_x], [flip_y])'''
 
  +
|name=spr
 
Draws a sprite, or a range of sprites, on the screen.
+
|shortdesc=Draws a sprite, or a range of sprites, on the screen.
 
|n||The sprite number. When drawing a range of sprites, this is the upper-left corner.
 
  +
|x||The x coordinate.
; n : The sprite number. When drawing a range of sprites, this is the upper-left corner.
 
; x, y : The x and y coordinates.
+
|y||The y coordinate.
; w, h : The width and height of the range, as a number of sprites. By default, the range is 1 wide, 1 high (one sprite).
+
|w|optional|The width of the range, as a number of sprites. Non-integer values may be used to draw partial sprites. The default is 1.0.
  +
|h|optional|The height of the range, as a number of sprites. Non-integer values may be used to draw partial sprites. The default is 1.0.
; flip_x : If <code>true</code>, the sprite is drawn inverted left to right. The default is <code>false</code>.
 
; flip_x : If <code>true</code>, the sprite is drawn inverted top to bottom. The default is <code>false</code>.
+
|flip_x|optional|If <code>true</code>, the sprite is drawn inverted left to right. The default is <code>false</code>.
 
|flip_y|optional|If <code>true</code>, the sprite is drawn inverted top to bottom. The default is <code>false</code>.
 
  +
}}
This draw operation is affected by the [[palette]], the [[camera]], and the [[clipping region]].
+
This operation is affected by the [[DrawState|draw state]].
   
 
== Examples ==
 
== Examples ==
  +
<syntaxhighlight lang="lua">
<pre>
 
 
-- draw sprite 1 (1x1) at (60, 60)
 
-- draw sprite 1 (1x1) at (60, 60)
 
spr(1, 60, 60)
 
spr(1, 60, 60)
Line 18: Line 19:
 
-- draw sprite 1 (1x1) at (72, 60), flipped vertically
 
-- draw sprite 1 (1x1) at (72, 60), flipped vertically
 
spr(1, 72, 60, 1, 1, false, true)
 
spr(1, 72, 60, 1, 1, false, true)
  +
  +
-- draw the top-left quarter of sprite 1 at (72, 60)
  +
spr(1, 72, 60, 0.5, 0.5)
   
 
-- draw sprite range starting at sprite 16, 3 wide 2 high, at (20, 52)
 
-- draw sprite range starting at sprite 16, 3 wide 2 high, at (20, 52)
 
spr(16, 20, 52, 3, 2)
 
spr(16, 20, 52, 3, 2)
  +
</syntaxhighlight>
</pre>
 
[[File:Spr ex1.png|thumb|220x220px]]
+
[[File:Spr ex1.png|thumb|center|220x220px|alt=The spr function in action.]]
[[File:Spr ex1 sprites.png|thumb|216x216px]]
+
[[File:Spr ex1 sprites.png|thumb|center|216x216px|alt=The sprite sheet used in this example.]]
   
 
== See also ==
 
== See also ==
   
 
* [[Graphics]]
 
* [[Graphics]]
* [[sspr]]
+
* [[DrawState|Draw state]]
  +
* [[Sspr|<code>sspr()</code>]]
* [[pal]]
 
* [[palt]]
+
* [[Pal|<code>pal()</code>]]
  +
* [[Palt|<code>palt()</code>]]
 
[[Category:Reference]]
 
[[Category:Reference]]
  +
[[Category:API]]

Revision as of 13:38, 15 June 2018

spr( n, x, y, [w,] [h,] [flip_x,] [flip_y] )
Draws a sprite, or a range of sprites, on the screen.
n
The sprite number. When drawing a range of sprites, this is the upper-left corner.

x
The x coordinate.

y
The y coordinate.

w
The width of the range, as a number of sprites. Non-integer values may be used to draw partial sprites. The default is 1.0.

h
The height of the range, as a number of sprites. Non-integer values may be used to draw partial sprites. The default is 1.0.

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

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

This operation is affected by the draw state.

Examples

-- draw sprite 1 (1x1) at (60, 60) 
spr(1, 60, 60)

-- draw sprite 1 (1x1) at (72, 60), flipped vertically
spr(1, 72, 60, 1, 1, false, true)

-- draw the top-left quarter of sprite 1 at (72, 60)
spr(1, 72, 60, 0.5, 0.5)

-- draw sprite range starting at sprite 16, 3 wide 2 high, at (20, 52)
spr(16, 20, 52, 3, 2)
The spr function in action.
The sprite sheet used in this example.

See also