Difference between revisions of "love.graphics.newQuad"
m (→Arguments: disambiguation) |
m |
||
(8 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
Creates a new [[Quad]]. | Creates a new [[Quad]]. | ||
+ | |||
+ | The purpose of a Quad is to use a fraction of a texture to draw objects, as opposed to drawing the entire texture. It is most useful for sprite sheets and atlases: in a sprite atlas, multiple sprites reside in the same texture, quad is used to draw a specific sprite from that texture; in animated sprites with all frames residing in the same texture, quad is used to draw specific frame from the animation. | ||
+ | |||
{{newobjectnotice}} | {{newobjectnotice}} | ||
== Function == | == Function == | ||
Line 7: | Line 10: | ||
</source> | </source> | ||
=== Arguments === | === Arguments === | ||
− | {{param|number|x|The top-left position in the [[ | + | {{param|number|x|The top-left position in the [[Texture]] along the x-axis.}} |
− | {{param|number|y|The top-left position in the [[ | + | {{param|number|y|The top-left position in the [[Texture]] along the y-axis.}} |
− | {{param|number|width|The width of the Quad in the [[ | + | {{param|number|width|The width of the Quad in the [[Texture]]. (Must be greater than 0.)}} |
− | {{param|number|height|The height of the Quad in the [[ | + | {{param|number|height|The height of the Quad in the [[Texture]]. (Must be greater than 0.)}} |
− | {{param|number|sw|The reference width, the width of the [[ | + | {{param|number|sw|The reference width, the width of the [[Texture]]. (Must be greater than 0.)}} |
− | {{param|number|sh|The reference height, the height of the [[ | + | {{param|number|sh|The reference height, the height of the [[Texture]]. (Must be greater than 0.)}} |
=== Returns === | === Returns === | ||
{{param|Quad|quad|The new Quad.}} | {{param|Quad|quad|The new Quad.}} | ||
− | |||
− | |||
+ | == Function == | ||
+ | {{newin|[[11.0]]|110|type=variant}} | ||
+ | === Synopsis === | ||
+ | <source lang="lua"> | ||
+ | quad = love.graphics.newQuad( x, y, width, height, texture ) | ||
+ | </source> | ||
+ | === Arguments === | ||
+ | {{param|number|x|The top-left position in the [[Texture]] along the x-axis.}} | ||
+ | {{param|number|y|The top-left position in the [[Texture]] along the y-axis.}} | ||
+ | {{param|number|width|The width of the Quad in the [[Texture]]. (Must be greater than 0.)}} | ||
+ | {{param|number|height|The height of the Quad in the [[Texture]]. (Must be greater than 0.)}} | ||
+ | {{param|Texture|texture|The texture whose width and height will be used as the reference width and height.}} | ||
+ | |||
+ | === Returns === | ||
+ | {{param|Quad|quad|The new Quad.}} | ||
== Examples == | == Examples == | ||
=== Use a Quad to display part of an Image: === | === Use a Quad to display part of an Image: === | ||
Line 26: | Line 42: | ||
-- Let's say we want to display only the top-left | -- Let's say we want to display only the top-left | ||
-- 32x32 quadrant of the Image: | -- 32x32 quadrant of the Image: | ||
− | top_left = love.graphics.newQuad(0, 0, 32, 32, img | + | top_left = love.graphics.newQuad(0, 0, 32, 32, img) |
-- And here is bottom left: | -- And here is bottom left: | ||
− | bottom_left = love.graphics.newQuad(0, 32, 32, 32, img | + | bottom_left = love.graphics.newQuad(0, 32, 32, 32, img) |
function love.draw() | function love.draw() | ||
love.graphics.draw(img, top_left, 50, 50) | love.graphics.draw(img, top_left, 50, 50) | ||
love.graphics.draw(img, bottom_left, 50, 200) | love.graphics.draw(img, bottom_left, 50, 200) | ||
− | |||
− | |||
− | |||
end | end | ||
</source> | </source> |
Latest revision as of 15:49, 9 March 2023
Creates a new Quad.
The purpose of a Quad is to use a fraction of a texture to draw objects, as opposed to drawing the entire texture. It is most useful for sprite sheets and atlases: in a sprite atlas, multiple sprites reside in the same texture, quad is used to draw a specific sprite from that texture; in animated sprites with all frames residing in the same texture, quad is used to draw specific frame from the animation.
![]() |
This function can be slow if it is called repeatedly, such as from love.update or love.draw. If you need to use a specific resource often, create it once and store it somewhere it can be reused! |
Contents
Function
Synopsis
quad = love.graphics.newQuad( x, y, width, height, sw, sh )
Arguments
number x
- The top-left position in the Texture along the x-axis.
number y
- The top-left position in the Texture along the y-axis.
number width
- The width of the Quad in the Texture. (Must be greater than 0.)
number height
- The height of the Quad in the Texture. (Must be greater than 0.)
number sw
- The reference width, the width of the Texture. (Must be greater than 0.)
number sh
- The reference height, the height of the Texture. (Must be greater than 0.)
Returns
Quad quad
- The new Quad.
Function
Available since LÖVE 11.0 |
This variant is not supported in earlier versions. |
Synopsis
quad = love.graphics.newQuad( x, y, width, height, texture )
Arguments
number x
- The top-left position in the Texture along the x-axis.
number y
- The top-left position in the Texture along the y-axis.
number width
- The width of the Quad in the Texture. (Must be greater than 0.)
number height
- The height of the Quad in the Texture. (Must be greater than 0.)
Texture texture
- The texture whose width and height will be used as the reference width and height.
Returns
Quad quad
- The new Quad.
Examples
Use a Quad to display part of an Image:
img = love.graphics.newImage("mushroom-64x64.png")
-- Let's say we want to display only the top-left
-- 32x32 quadrant of the Image:
top_left = love.graphics.newQuad(0, 0, 32, 32, img)
-- And here is bottom left:
bottom_left = love.graphics.newQuad(0, 32, 32, 32, img)
function love.draw()
love.graphics.draw(img, top_left, 50, 50)
love.graphics.draw(img, bottom_left, 50, 200)
end
See Also
Other Languages
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info