SpriteBatch:flush

Available since LÖVE 0.9.2
This function is not supported in earlier versions.

Immediately sends all new and modified sprite data in the batch to the graphics card.

Normally it isn't necessary to call this method as love.graphics.draw(spritebatch, ...) will do it automatically if needed, but explicitly using SpriteBatch:flush gives more control over when the work happens.

If this method is used, it generally shouldn't be called more than once (at most) between love.graphics.draw(spritebatch, ...) calls.

Function

Synopsis

SpriteBatch:flush( )

Arguments

None.

Returns

Nothing.

Examples

Initialize a static spritebatch with sprites and immediately send the data to the graphics card

function love.load()
    image = love.graphics.newImage("tile.png")
    spritebatch = love.graphics.newSpriteBatch(image, 20 * 20, "static")

    for y = 1, 20 do
        for x = 1, 20 do
            spritebatch:add((x - 1) * 64, (y - 1) * 64)
        end
    end

    -- If we call SpriteBatch:flush now then it won't be called internally when the SpriteBatch is drawn for the first time.
    -- In other words, we're choosing to do the work in love.load instead of the first love.draw.
    spritebatch:flush()
end

function love.draw()
    love.graphics.draw(spritebatch, 0, 0)
end

See Also

Other Languages