newArrayImage

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
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

newArrayImage

Post by Ref »

Just curious!
What's the big deal?

Code: Select all

sprites = { "sprite1.png",  "sprite2.png" }
image = love.graphics.newArrayImage( sprites )
batch = love.graphics.newSpriteBatch( image )
batch:addLayer( #, x, y  )
Isn't a batch just a limited canvas - the limitation is that all the sprites have to be the same size?
To make any change to the batch, you have to recreate it - just like drawing everything again to a canvas.
With a canvas, the sprites can be any size.
Any speed advantage? Don't think so.
What am I missing?
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: newArrayImage

Post by zorg »

love.graphics.newArrayImage
or if you want to look into it more in-depth
Basically, it apparently gives solutions to texture bleeding that regular atlases have if you don't pad the image or something like that.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: newArrayImage

Post by pgimeno »

Ref wrote: Wed Apr 18, 2018 4:32 pm Isn't a batch just a limited canvas - the limitation is that all the sprites have to be the same size?
To make any change to the batch, you have to recreate it - just like drawing everything again to a canvas.
With a canvas, the sprites can be any size.
Any speed advantage? Don't think so.
What am I missing?
No, a batch and a canvas are very different things.

A canvas can be seen as a special kind of texture that you can draw to. A batch, however, is a collection of quads of an image. It's more similar to a mesh; the main difference is that in a mesh, you have full control over the triangles, but in a batch, you are limited to adding pairs of triangles that form rectangles.

You can actually update a batch, that's what SpriteBatch:set is for, but it's often simpler to just recreate it.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: newArrayImage

Post by Ref »

Interesting INFO!
(It seems from the WIKI that you can use batches in a variety of different ways - using individual images or quads and a spritesheet. )
I have found (using WIKI example) that:

Code: Select all

sprites = { "sprite1.png",  "sprite2.png" }
image = love.graphics.newArrayImage( sprites )
batch = love.graphics.newSpriteBatch( image )
id[i] = batch:addLayer( i, pos[i][1], pos[i][2] )
doesn't get reset properly using:

Code: Select all

batch:set(id[2],pos[2][1],pos[2][2])
Gets the correct new image position but wrong image (sprite[1] and not sprite[2]).
More head scratching needed.
Edit: Head scratching worked - use the following:

Code: Select all

batch:setLayer( 2, id[2],  pos[2][1],  pos[2][2]  )
where '2' is the layer and id[#] is image.
Post Reply

Who is online

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