1. Anders Ruud
  2. love
  3. Issues

Issues

Issue #699 wontfix

SpriteBatch identifiers starting at 1

hahawoo
created an issue

SpriteBatch identifiers seem to start at 0, perhaps it would be better if they started at 1? It could be fun for setting them within loops.

Comments (4)

  1. hahawoo reporter

    Ah, I chose a bad name then. :P

    Wouldn't starting at 1 be sometimes useful-ish though, more often than starting at 0 would be?

    Like, in this silly example:

    function love.load()
        imagedata = love.image.newImageData(30, 30)
        imagedata:mapPixel(function(x, y) return 255, x*5, y*5, 255 end)
        image = love.graphics.newImage(imagedata)
        number = 100
        spritebatch = love.graphics.newSpriteBatch(image, number, 'stream')
        t = {}
        for i = 1, number do
            t[i] = {
                x = math.random(1, 100),
                y = math.random(1, 100),
                dx = math.random(10, 100),
                dy = math.random(10, 100),
            }
            spritebatch:add(t[i].x, t[i].y)
        end
    end
    
    function love.update(dt)
        for i = 1, number do
            t[i].x = t[i].x + t[i].dx * dt
            t[i].y = t[i].y + t[i].dy * dt
            spritebatch:set(i, t[i].x, t[i].y)
        end
    end
    
    function love.draw()
        love.graphics.draw(spritebatch)
    end
    

    Making this work is as simple as changing spritebatch:set(i to spritebatch:set(i-1, or storing the identifier returned by add in each table.

    However, I guess it's an example of when starting at 1 would be nicer than starting at 0. And at least starting at 1 would prevent people from wondering why it doesn't start at 1. :P

  2. Bart van Strien

    Well, more importantly, the fact it's an id, not an index means it can be in any order, starting from anywhere. That they turn out to be array indexes internally is only an implementation detail.

  3. Log in to comment