{{newin|[[11.0]]|110|type=function}}
Adds a sprite to a batch created with an [[TextureType|Array Texture]].

== Function ==
Adds a layer of the SpriteBatch's Array Texture.
=== Synopsis ===
<source lang="lua">
spriteindex = SpriteBatch:addLayer( layerindex, x, y, r, sx, sy, ox, oy, kx, ky )
</source>
=== Arguments ===
{{param|number|layerindex|The index of the layer to use for this sprite.}}
{{param|number|x (0)|The position to draw the sprite (x-axis).}}
{{param|number|y (0)|The position to draw the sprite (y-axis).}}
{{param|number|r (0)|Orientation (radians).}}
{{param|number|sx (1)|Scale factor (x-axis).}}
{{param|number|sy (sx)|Scale factor (y-axis).}}
{{param|number|ox (0)|Origin offset (x-axis).}}
{{param|number|oy (0)|Origin offset (y-axis).}}
{{param|number|kx (0)|Shearing factor (x-axis).}}
{{param|number|ky (0)|Shearing factor (y-axis).}}
=== Returns ===
{{param|number|spriteindex|The index of the added sprite, for use with [[SpriteBatch:set]] or [[SpriteBatch:setLayer]].}}

== Function ==
Adds a layer of the SpriteBatch's Array Texture using the specified [[Quad]].
=== Synopsis ===
<source lang="lua">
spriteindex = SpriteBatch:addLayer( layerindex, quad, x, y, r, sx, sy, ox, oy, kx, ky )
</source>
=== Arguments ===
{{param|number|layerindex|The index of the layer to use for this sprite.}}
{{param|Quad|quad|The subsection of the texture's layer to use when drawing the sprite.}}
{{param|number|x (0)|The position to draw the sprite (x-axis).}}
{{param|number|y (0)|The position to draw the sprite (y-axis).}}
{{param|number|r (0)|Orientation (radians).}}
{{param|number|sx (1)|Scale factor (x-axis).}}
{{param|number|sy (sx)|Scale factor (y-axis).}}
{{param|number|ox (0)|Origin offset (x-axis).}}
{{param|number|oy (0)|Origin offset (y-axis).}}
{{param|number|kx (0)|Shearing factor (x-axis).}}
{{param|number|ky (0)|Shearing factor (y-axis).}}
=== Returns ===
{{param|number|spriteindex|The index of the added sprite, for use with [[SpriteBatch:set]] or [[SpriteBatch:setLayer]].}}
=== Notes ===
The specified layer index overrides any layer index set on the Quad via [[Quad:setLayer]].

== Function ==
Adds a layer of the SpriteBatch's Array Texture using the specified [[Transform]].
=== Synopsis ===
<source lang="lua">
spriteindex = SpriteBatch:addLayer( layerindex, transform )
</source>
=== Arguments ===
{{param|number|layerindex|The index of the layer to use for this sprite.}}
{{param|Transform|transform|A transform object.}}
=== Returns ===
{{param|number|spriteindex|The index of the added sprite, for use with [[SpriteBatch:set]] or [[SpriteBatch:setLayer]].}}

== Function ==
Adds a layer of the SpriteBatch's Array Texture using the specified [[Quad]] and [[Transform]].
=== Synopsis ===
<source lang="lua">
spriteindex = SpriteBatch:addLayer( layerindex, quad, transform )
</source>
=== Arguments ===
{{param|number|layerindex|The index of the layer to use for this sprite.}}
{{param|Quad|quad|The subsection of the texture's layer to use when drawing the sprite.}}
{{param|Transform|transform|A transform object.}}
=== Returns ===
{{param|number|spriteindex|The index of the added sprite, for use with [[SpriteBatch:set]] or [[SpriteBatch:setLayer]].}}
=== Notes ===
The specified layer index overrides any layer index set on the Quad via [[Quad:setLayer]].

== Notes ==
In order to use an Array Texture or other non-2D texture types as the main texture in a custom [[Shader]], the [[love.graphics.newShader|void effect()]] variant must be used in the pixel shader, and MainTex must be declared as an ArrayImage or sampler2DArray like so: <code>uniform ArrayImage MainTex;</code>.

== Examples ==
=== Draw multiple layers of an Array Image in a SpriteBatch ===
<source lang="lua">
function love.load()
    local sprites = {"sprite1.png", "sprite2.png"}
    image = love.graphics.newArrayImage(sprites)

    batch = love.graphics.newSpriteBatch(image)
    batch:addLayer(1, 50, 50)
    batch:addLayer(2, 250, 50)
end

function love.draw()
    love.graphics.draw(batch)
end
</source>

=== Use a custom shader ===
<source lang="lua">
shader = love.graphics.newShader[[
uniform ArrayImage MainTex;

void effect() {
    // Texel uses a third component of the texture coordinate for the layer index, when an Array Texture is passed in.
    // love sets up the texture coordinates to contain the layer index specified in love.graphics.drawLayer, when
    // rendering the Array Texture.
    love_PixelColor = Texel(MainTex, VaryingTexCoord.xyz) * VaryingColor;
}
]]

function love.load()
    local sprites = {"sprite1.png", "sprite2.png"}
    image = love.graphics.newArrayImage(sprites)

    batch = love.graphics.newSpriteBatch(image)
    batch:addLayer(1, 50, 50)
    batch:addLayer(2, 250, 50)
end

function love.draw()
    love.graphics.setShader(shader)
    love.graphics.draw(batch)
end
</source>

== See Also ==
* [[parent::SpriteBatch]]
* [[SpriteBatch:setLayer]]
* [[love.graphics.newArrayImage]]
* [[love.graphics.newCanvas]]
* [[love.graphics.newShader]]
* [[TextureType]]
[[Category:Functions]]
{{#set:Description=Adds a sprite to a batch created with an [[TextureType|Array Texture]].}}
== Other Languages ==
{{i18n|SpriteBatch:addLayer}}