Hello ! I'll try to explain this as good as possible.
So, i have a tilebased map.
Right now i draw it using two for-loops like normal.
The tiles in my game are 64x64 but some tiles are taller then that so you can walk behind them like a 3d effect.
I draw the character in the for loops if his Y is the same as the loops Y.
So If you stand behind the tile you are drawn before it (behind it). If you stand infront of it you are draw after (on top of it)
So i've read up alittle bit about Spritebatches but im not sure how i would get this same effect with a spritebatch.
Any help would be veeery appriciated
/fe
Efficent tile with 3d effect and spritebatch
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- DaedalusYoung
- Party member
- Posts: 407
- Joined: Sun Jul 14, 2013 8:04 pm
Re: Efficent tile with 3d effect and spritebatch
I've been thinking about this, but not tried it yet, but I think you'd need 2 Spritebatches, and they'll both change a lot.
The basic idea is that you have one Spritebatch that is drawn first, then draw the player and then draw the second Spritebatch. The first batch only contain the tiles up to the character's y coordinate and the second batch contains the tiles from the character's y coordinate until the end. Whenever the character's y coordinate changes, you add/delete one row of sprites from one Spritebatch and delete/add it from the second.
Another method is to make a separate Spritebatch for each row of tiles, which will still decrease the number of draw calls significantly. You'll still change these batches whenever the screen layout changes.
And finally, you can ask yourself if the current method is really slowing down your framerate. If it isn't, you can just leave it as it is.
The basic idea is that you have one Spritebatch that is drawn first, then draw the player and then draw the second Spritebatch. The first batch only contain the tiles up to the character's y coordinate and the second batch contains the tiles from the character's y coordinate until the end. Whenever the character's y coordinate changes, you add/delete one row of sprites from one Spritebatch and delete/add it from the second.
Another method is to make a separate Spritebatch for each row of tiles, which will still decrease the number of draw calls significantly. You'll still change these batches whenever the screen layout changes.
And finally, you can ask yourself if the current method is really slowing down your framerate. If it isn't, you can just leave it as it is.
Re: Efficent tile with 3d effect and spritebatch
If you use Tiled Map Editor (www.mapeditor.org) then you can use my Tiled library (see my sig) that already allows for this.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+
Dev Blog | GitHub | excessive ❤ moé
LÖVE3D - A 3D library for LÖVE 0.10+
Dev Blog | GitHub | excessive ❤ moé
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Efficent tile with 3d effect and spritebatch
If I were in your situation and I were to use SpriteBatches, I would make one spritebatch per "row of tiles".
The tile rows would have a 'y' coordinate, and so would have the entities of the game (the player, the enemies, etc). You can get the visible rows, the visible entities, sort them by y, and draw from top to bottom.
The pseudo-code would look like this:
The tile rows would have a 'y' coordinate, and so would have the entities of the game (the player, the enemies, etc). You can get the visible rows, the visible entities, sort them by y, and draw from top to bottom.
The pseudo-code would look like this:
Code: Select all
local function sort_by_y(a,b)
return a.y < b.y
end
function love.draw()
local rows = get_visible_map_rows(camera)
local entities = get_visible_entities(camera)
local visible = array_concat(rows, entities)
table.sort(visible, sort_by_y)
for i=1,#visible do
draw_entity_or_row_sprite_batch(visible[i])
end
end
When I write def I mean function.
Who is online
Users browsing this forum: No registered users and 224 guests