Simple textured D3D tile map

Started by
11 comments, last by Lightstrike 20 years, 2 months ago
Hi, There''s been a few posts about this before but I want a clear response so I know what do to. I haven''t found a good source anywhere here or on the internet. Here''s the situation: We''ve currently made a map by rendering an alpha-textured quad X times which means roughly doubled amount of vertices and 4 times as many pixels are drawn than necessary. How would you make a simple textured 2d-map in Direct3d with nice transitions between the tiles and no redundant use of vertices? It would be nice if you could make a list of things I need to look up or think about and even some pseudo code if you feel like it. This would greatly enhance the performance of our game and help more people play it. Thanks for your help! Ask if something isn''t clear.
Advertisement
I''m a bit unclear as to what you are saying. Are you doing a first pass of tiles and then doing a blended pass for your transitions?
No, we are making a drawprimitive call for each tile with a texture that is alphablended in the edges so they overlap to create the transition.
Does noone make simple terrain here? Someone gotta have an idea. I appreciate any help or links to good tutorials and the like.
Good luck finding any help.

I''ve had the same problem but it is damn near impossible to find what we need. My engine also uses a drawprimitive for each tile and the performance is mediocre. I get double the FPS using the summer update and LPD3DXSPRITE interface. However, using that doesn''t even get me a 3rd the FPS I can get with my 2D directdraw engine....but I get alpha with it. :-)

Sadly, most people in these forums are for 3D shooters only. Not many great coders in here program 2D games.

cb
Rock the cradle of love! You stupid WANKER!
Some imagination could help you here, just make what you do in 2D maps, create (maybe in load time) a set of tiles of your transitions, then the only thing you need to do is a drawprimitive for each texture in your map

Or maybe draw a simple tile-map an then re-render the transition sections with alpha

---------------------------------------------
If God with me, Who against me?
Sitio de desarrollo de videojuegos en español
Digital Moon Studio...

There is no spoon
--------------------------------------------- If God with me, Who against me?Personal Web Samuel Prince Blog...
Thanks for your answers. You are right coleco. Way too many spend their time trying to do 3d games when you can actually complete 2d games that are fun.

The thing is we already have tried the "drawprimitive for all tiles" version. We would like to advance a step and create the triangles that form the map and texture it with nice transitions using direct3d and then drawing the whole thing with a single drawprimitive call which would increase performance significantly.
Don't knock 3D Programmers, some of us have more of an interest in 3D than 2D beyond the scope of '3D is all the rage, 2D s0xxx0rz' or something like that. I do 3D because I find it fascinating and more 'beautiful' when it works. I've got a 2D DirectDraw engine too =P

Anyways:
I'm assuming here you're talking about something like Super Mario Bros. or such? You're not perfectly clear. If thats the case, why don't you take your map and build a vertex buffer out of the entire map, along with an index buffer.

Then use your camera to decide what tiles to draw from the index buffer.

----

Also make sure you're batching your tiles by texture. If you draw your textures like this:
AAAABBAABBAACAACCAAA
You're going to see a huge performance hit. Sort your tiles by texture and draw them that way, so textures come out like:
AAAAAAAAAAAAAABBBCCC

It shouldn't make a difference for your background layer tiles. When you're drawing your sprites, sort by the Y or Z or whatever co-ordinate system you use.

[edited by - GroZZleR on February 12, 2004 5:07:22 PM]
Thanks for your reply GroZZler. I didn't mean to offend 3d programmers. There are lots of incredibly skilled programmers here. I meant those who went directly from directdraw to making mmorpgs and think they will make it.

I'll try to clear things up.

We have a x,y-plane of tiles (two triangles each) seen from above showing terrain. Take a look at our game to see how it is now (Click to games page and scroll down for screenshots): Homepage

Right now we do like this (in simplest pseudocode possible):

for every texturetype (tiletype)
settexture(texture)
for x coords on screen
for y coords on screen
if(tiletype == texture)
DrawPrimitive(x, y)

What we want to do now is:

1. Do this the most optimal way. How do I set up vertex and index buffers and textures when loading the map so we can draw the fewest times with best performance and memory requirements.

2. Calculate smooth transitions between the different kinds of textures so there's no visible cuts between them.

Hope this helps. Thanks for your help.

[edited by - Lightstrike on February 12, 2004 5:33:05 PM]
Hrm.. You''re already sorting by texture, so thats a great start. You know, you could probably use a heightmap rip-off here and it''d work perfectly. Just don''t include a height value.

Assuming you store your map in a square, similar to something like this: (Where o = Road, T = Terrain, etc.. etc..)
TooT
oTTo
TooT

Check out this tutorial. Look at Figure 8.2 near the bottom. Thats pretty much exactly what you want.

Its in 3D, but I''m sure you could just position the camera overhead like you have now with no problem. Just play around with it.

As for making nice textured flowing terrain, I really don''t know. I''m trying to do the same as you with heightmaps =P

Good luck.

This topic is closed to new replies.

Advertisement