objects in tilemap that uses spritebatch
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
objects in tilemap that uses spritebatch
So I use a spritebatch for my tiles. I have a ground layer, object layer, and foreground layer. The ground layer and object layer use 1 spritebatch that uses 1 tilesheet of scenery tiles. The object layer is for actors and obviously use a different tilesheet. The drawing order is ground, object, foreground. So if I have 1 spritebatch for the scenery and 1 for the actors I don't see how can I get this draw order?
Re: objects in tilemap that uses spritebatch
"Sprites are drawn in the order they are added." It is the only order you have, I don't think it is possible to change it. Has you use many tile I don't see many solution :
- use a series of spritebatch for each layer.
It is the way I do. So I call for each object object.draw that had the tile into the spritebatch of its layer. and then I draw spritebatch in the right order.
I don't think it is critical, it only multiply the number of spritebatch by the number of layer. Also tile can be different between layers so it is less than that.
I hope it helps you.
- use a series of spritebatch for each layer.
It is the way I do. So I call for each object object.draw that had the tile into the spritebatch of its layer. and then I draw spritebatch in the right order.
I don't think it is critical, it only multiply the number of spritebatch by the number of layer. Also tile can be different between layers so it is less than that.
I hope it helps you.
Re: objects in tilemap that uses spritebatch
Thanks for the reply. I was thinking about this but since the ground layer and foreground layer use the same image I wonder if that image is sent and stored on the gfx card twice when creating 2 spritebatches or does love know this is what is happening and it's shared? Seems like it would be a waste of memory on the video card to have the same image stored twice. Do you know if this is what is happening when you do this? This seems like it could negate some of the benefits of spritebatches so I thought there must be another way but maybe there isn't.
Re: objects in tilemap that uses spritebatch
I thought there was a waste of memory but I made a program that seem to show the opposite.
I set the image of the spritebatch and then I shift the filter of the image.
it result in changing the filter of the image of the spritebatch
So I think the spritebatch have a pointer to the image and so making two spritebatch doesn't copy the image twice.
I set the image of the spritebatch and then I shift the filter of the image.
it result in changing the filter of the image of the spritebatch
So I think the spritebatch have a pointer to the image and so making two spritebatch doesn't copy the image twice.
- Attachments
-
- spritebatch.love
- (2.87 KiB) Downloaded 130 times
Re: objects in tilemap that uses spritebatch
What do you mean you "shift the filter of the image"? I don't understand what that means (sorry I'm new to Love).
Re: objects in tilemap that uses spritebatch
I make image:setFilter("nearest) when I press "n" and image:setFilter("linear") when I press "l"
you can take a look at the code by unzip the .love file
you can take a look at the code by unzip the .love file
Code: Select all
1 function love.load()
2 image=love.graphics.newImage("character.png")
3 sb=love.graphics.newSpriteBatch(image)
4 sb:add(100,0,0,10,10)
5 end
6
7 function love.draw()
8 love.graphics.draw(image,0,0,0,10,10)
9 love.graphics.draw(sb,0,0)
10 love.graphics.print("press l or n")
11 end
12
13 function love.keypressed(key)
14 if key == "escape" then
15 love.event.quit()
16 elseif key == "l" then
17 image:setFilter("linear")
18 elseif key == "n" then
19 image:setFilter("nearest")
20 end
21 end
Re: objects in tilemap that uses spritebatch
Oh, so you are saying you notice that all batches reflect this change to the 1 image they share so it must be a pointer to the 1 image. I see. Thanks for your help!
Who is online
Users browsing this forum: No registered users and 3 guests