Difference between revisions of "SpriteBatch:flush"

m
m (Initialize a static spritebatch with sprites and immediately send the data to the graphics card)
 
(One intermediate revision by the same user not shown)
Line 4: Line 4:
 
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 between love.graphics.draw(spritebatch, ...) calls.
+
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 20: Line 20:
 
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 37: Line 37:
 
end
 
end
 
</source>
 
</source>
 +
 
== See Also ==
 
== See Also ==
 
* [[parent::SpriteBatch]]
 
* [[parent::SpriteBatch]]

Latest revision as of 02: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