I Need Some Refresher Tips on SpriteBatch

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
sphyrth
Party member
Posts: 260
Joined: Mon Jul 07, 2014 11:04 am
Contact:

I Need Some Refresher Tips on SpriteBatch

Post by sphyrth »

I haven't used SpriteBatch for a long time. In fact, I was using them back when the bind and unbind functions were still used.

Now, for simplicity's sake this is how my SpriteBatch should look like now:

Code: Select all

function love.load()
   img_tiles = love.graphics.newImage('tiles.png')
   spr_tiles = love.graphics.newSpriteBatch(img_tiles, 2)

   local w, h = img_tiles:getDimensions()
   tile = {}
   tile[1] = love.graphics.newQuad(0,  0, 10, 10, w, h)
   tile[2] = love.graphics.newQuad(0, 15, 10, 10, w, h)

   updateBatch()
end

function love.update(dt)
   updateBatch()
end

function love.draw()
   love.graphics.draw(spr_tiles)
end

function updateBatch()
   spr_tiles:clear()

   -- Too lazy to loop, but took the effort of writing this comment
   spr_tiles:add(tile[1], 1, 1)
   spr_tiles:add(tile[2], 1, 11)
   
   spr_tiles:flush()
end
I'm currently following the Efficient Tile-based Scrolling for this example.

I just realized that my first mistake is that I was always running updateBatch() on love.update(dt). Other than that, I have no idea on what to improve upon.

Any suggestionss?
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 43 guests