2D Map Sprite Visibility Detection

D63afd03aea884a4812d1d7360593316
0
Annihilator 101 Dec 26, 2012 at 11:57 algorithm collision culling

Hello.

Can anyone please share an example or a link to the information about 2D Game map spritie visibility detection?
I have googled for a while now and only found the way to render 2D tile maps which is easy.

What i am looking for is a basic info on how to Render what is visible in the camera and not render invisible objects.
My project has a map with few big ground textures and a lot of objects placed on top in the Editor. Objects are not snapped to a grid and can be places anywhere in a free-form way (can be stretched, rotated). Basically i am moving around the map, and placing the objects anywhere i want.

What I am looking for is how to detect what sprites are in the viewport and only render them.

Thanks.
Juris.

3 Replies

Please log in or register to post a reply.

B5262118b588a5a420230bfbef4a2cdf
0
Stainless 151 Dec 26, 2012 at 12:08

If you want sprites which block the view of other sprites, look at 2D lighting techniques. There are loads of examples.

Otherwise it’s a simple matter of checking which sprites intersect with the view rectangle.

D63afd03aea884a4812d1d7360593316
0
Annihilator 101 Dec 26, 2012 at 12:24

@Stainless

Otherwise it’s a simple matter of checking which sprites intersect with the view rectangle.

Yes, i have thought about it. but what if the map is huge and we have like 10.000 sprites, starting from small dirt, stones, grass textures
up to trees, buildings, NPCs ? Then looping through array that huge is not a good idea. That is what i have right now. And In the future,
our maps might have a lot more then 10.000 sprites, as the Artist has a full freedom to load the editor and place any objects anywhere.

It is a top down 2d map and i am looking for a way to detect visible sprites for that and not having to go through a loop of all sprites. Any ideas?

B5262118b588a5a420230bfbef4a2cdf
0
Stainless 151 Dec 26, 2012 at 19:33

Then use a partitioning system

to allow for dynamic allocation, I would simply use regions. Divide the world into say a 16 by 16 space and create a class which contains all the sprites in that region

You could make each class cover the visible region. So depending on view direction and position you may only have to check 4 regions

Say you have 10,000 sprites in the map evenly distributed, then each cell would contain about 40 sprites. So at most you will have to check 160