Sign in to follow this  

2D Tile Confusion

This topic is 4837 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

O.K. This may be a stupid question but the more information I read the more confused I become. I am in the planning stages of creating a simple 2D Tile game and have conflicting ideas on how to go about this. Do I load all the tiles to a surface, copy them to the back buffer and then copy other tiles over them using a Blt() function to handle transparency. OR would I be able to create the entire thing using textured quads with alpha values? If so which one is better? Also the material I read about using tex. quads only shows how to load them from a file, which I understand to mean that each tile would need to be in a seperate file for the function did not allow for coordinates on the source image. Is there a way to pick a certain portion of a file (or even surface) to be used as a texture? Any and all advice would be greatly appreciated. Thanks.

Share this post


Link to post
Share on other sites
A textured quad is 2 primitives arranged in a quadralateral with a texture applied over them.

Basically, you'd make a grid of these, and just render them. Not too difficult - I'd say definately use the textured quads. I've never heard of it being done with surfaces - probably slower.

But if you are concerned with speed, I'd say benchmark it!

EDIT:

just saw that you're using blt() which means you're using DX7... I'd actually suggest you include the alpha textures in your texture files to speed things up... my benchmarks with Dx8 show that using a colorkey (same as blting out alphavalues on a texture) on a 256x256 more than doubles the load time, triples in some circumstances. Though it may just be my code, it's definitely faster to have alpha values already in the texures.

I'm pretty sure D3D8 is basically the same in D3D7, but part of the vertex structure should be texture coordinates, tu and tv. You use these to position the texture over the quad. You should only need one instance of each texture, not one per tile. That would take up too much space!


Mushu - trying to help those he doesn't know, with things he doesn't know.
Why won't he just go away? An question the universe may never have an answer to...

Share this post


Link to post
Share on other sites
Thanks, but now my question is, how do I load multiple textures from 1 file? The method I have seen is LoadTextureFromFile which means that the entire file is one texture, therefore one tile. Or is there a way to either load a tileset as 1 texture and then only use pieces of it or load the tileset to a surface and then create textures from pieces of the surface?

Share this post


Link to post
Share on other sites
Honestly, my advice would be to just have each texture be a different file. Especially if you change them frequently, it can be a real hassel trying to manage a number of textures on a single file. If your game is going to have hundreds of textures, then yes, go with a single file.

Anyways, if you choose to go the single file route.. You can use the LockRect() function (do a search on MSDN for the exact usage). You basically specify the MIP texture level you want to lock, and a RECT describing the coordinates.

The function will return you a pointer to the starting bit of the data. Then you can simply read however much you want using simple math (depending on how many bits each pixel is... say 32 bit D3DFMT_A8R8G8B8). Then do the simple multiplication/addition to go from row to row storing each pixel as you go.

Also, be careful not to use the width of the row when you do your calculations. You want to use the pitch, as some drivers add extra data to the end of each row for efficiency, so the width might not be correct.

Hope that helps :)

Share this post


Link to post
Share on other sites

This topic is 4837 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this