Optimal way to place objects/tiles in right order?

BlitzMax Forums/BlitzMax Beginners Area/Optimal way to place objects/tiles in right order?

Nest(Posted 2012) [#1]
I have all of my game entities in EntityList

I have my level stored in a 2D array (0 = nothing, 1 = solid).

I know how to order my sprites by their Y value to draw them so they don't overlap each other.

What I want to know is an optimal way to draw my sprites and tiles such that the sprites appear behind walls where appropriate.

The only way I can think of it at the moment is to cycle through all of the sprites to see if they are within a tile for every tile I render, but this doesn't seem that efficient.

The other way I can think of is to group up my sprites into their Y-tile value, so that I can do the same as above but only check the ones that are known to be in the current row - slightly more efficient but there has to be a better way.

How about sticking my tiles (that aren't empty) into the same list as the entities and order/draw them all that way?

Thanks for any help you can provide.




Who was John Galt?(Posted 2012) [#2]
I would probably have an entity list associated with each tile, stick my 'actors' in the correct list and have the renderer draw the contents of the associated entity list along with each tile. Similar to your last idea.

Love the retro graphics, BTW. Brings to mind 'Mad Doctor' on the C64 if you ever heard of that.


Nest(Posted 2012) [#3]
Thanks, I'll give it a go - yeah I love the pixelated style, I just cracked isometric transformation so I'm on a mad programming spree now!


GfK(Posted 2012) [#4]
Reminds me of D/Generation (which was a cracking game!)


Nest(Posted 2012) [#5]
I had a demo of that from a copy of Amiga Format!


Nest(Posted 2012) [#6]
Sorted it!

I gave each entity a "current tile" variable, then on drawing the map I loop through the EntityList to see if their x/y matches, then draw them if so. Not sure if optimal but works perfectly for now!

Cheers all.

edit: added some textures and managed to add a transparency effect to see yourself behind the wall. Did this by a second pass on drawing all entities with a 0.3 alpha.



Last edited 2012


Nest(Posted 2012) [#7]
My next challenge :|




Derron(Posted 2013) [#8]
The bottom of the "clipping" tile is ending "later" than the figure but this tile is on a level+1 so this is not allowed.

For your problems you will find dozens of tutorials on the net...just binggooglealtavista for it.


bye
Ron


Nest(Posted 2013) [#9]
Cheers Ron, I'm aware of what's causing it and inadvertently came across a few articles regarding it before I encountered the problem myself. In my enthusiasm I wanted to give the helpful people an update; I really didn't intend to come across as someone who is incapable of using the endless resources available to solve a common problem.


Derron(Posted 2013) [#10]
For people whose mother tongue isn't English it isn't as easy to find suitable information for all their problems... - and this includes me too.

And as you updated for a new problem it didn't let me think of "he used a ressource having all algorithms ready to use" but an "he tries to do it by himself".

Glad you get it fixed.


bye
Ron


Nest(Posted 2013) [#11]
Thanks, while I can't get to my PC until later, I think if I move the "what tile is my sprite in" check to the closest point of the image to the camera (in this instance the lower left corner), it should fix it. I am looking forward to trying it later. :)