Difference between revisions of "SpriteBatch:flush"

(Created page)
 
m (Initialize a static spritebatch with sprites and immediately send the data to the graphics card)
 
(2 intermediate revisions by the same user not shown)
Line 3: Line 3:
  
 
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.
 
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 ==
 
== Function ==
Line 14: Line 16:
 
Nothing.
 
Nothing.
 
== Examples ==
 
== Examples ==
=== Initialize a static SpriteBatch with sprites and immediately send the data to the graphics card ===
+
=== Initialize a static spritebatch with sprites and immediately send the data to the graphics card ===
 
<source lang="Lua">
 
<source lang="Lua">
 
function love.load()
 
function love.load()
 
     image = love.graphics.newImage("tile.png")
 
     image = love.graphics.newImage("tile.png")
     spritebatch = love.graphics.newSpriteBatch(image, 25 * 25, "static")
+
     spritebatch = love.graphics.newSpriteBatch(image, 20 * 20, "static")
  
     for y = 1, 25 do
+
     for y = 1, 20 do
         for x = 1, 25 do
+
         for x = 1, 20 do
             spritebatch:add((x - 1) * 100, (y - 1) * 100)
+
             spritebatch:add((x - 1) * 64, (y - 1) * 64)
 
         end
 
         end
 
     end
 
     end
Line 35: Line 37:
 
end
 
end
 
</source>
 
</source>
 +
 
== See Also ==
 
== See Also ==
 
* [[parent::SpriteBatch]]
 
* [[parent::SpriteBatch]]

Latest revision as of 00:36, 29 August 2014

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