Jump to content
  • Advertisement
Sign in to follow this  
thallish

2d Scroller - thoughts about tiling

This topic is 4764 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

hi I'm currently involved with creating my own tiling engine for a 2d scroller and I have some thoughts that are nacking me. The way I do it now is that I use a vertex format D3DFVF_XYZ | D3DFVF_TEX1 and I'm wondering if it would be more useful to use taransformed coordinates, since I have to transform the specific tiles anyway (D3DFVF_XYZRHW)? Does this sound correct? If not how do i transform the world coordinate (0.0f,0.0f,0.0f) to be at the lower left corner of the screen? or upper left, dosen't matter Well I'm filling up a vertexbuffer with a struct like this
CUSTOMTILEVERTEX vertices[] =
{
{ 0.0f, 0.0f, 1.0f, 0, 1},// x, y, z, u, v
{ 0.0f, 1.0f, 1.0f, 0, 0},
{ 1.0f, 1.0f, 1.0f, 1, 0},
{ 1.0f, 0.0f, 1.0f, 1, 1} 
};

and then I have a function to draw the tile with a specific texture. But how do I change the coordinates of the tile? I started out with locking, filling up the vertexbuffer, and then unlocking again for every single tile but thats a real performance eater, so down the drain with that. Is there another way i can manipulate (0.0, 0.0, 0.0) to be at different places depending on where the tile should be drawn? Well the last thought is about sprites. I have this idea that sprites is mostly useful for moving objects in a game. Does this idea make sence? Or should every tile be a sprite? I hope some of you more experienced guys can give me some pointers. Make me wiser ;-) regards thallish

Share this post


Link to post
Share on other sites
Advertisement
I'd recommend using the ID3DXSprite inteface. Its simple, you can use screen cordinates and you can specify a section of a texture in pixels instead of texels.

Other than that I'd recommend using pretransformed vertices, since you probably won't need 3D for anything in a 2D sidescroller.

To move your vertices, you need to use D3DXMatrixTransformation.

Share this post


Link to post
Share on other sites
Quote:

I started out with locking, filling up the vertexbuffer, and then unlocking again for every single tile but thats a real performance eater,


Yes, i bet it is. The keys are indexbuffer and batching.
Look here.
First, setup your vertex- and indexbuffer. Then, you lock your vertex-buffer once and set your texture (the tileset).
Then you loop through your map and for every cell you add a quad to your vertexbuffer. Every cell of your map holds an integer value, representing the tile index (ie the part of your tileset-texture) to be rendered.
Based upon that index, you calculate the x and the y value, convert to UV coordinates and set those for the vertex of the quad before add it to the vertexbuffer.
Finally, unlock your vertexbuffer, set stream source and draw.
Doing so, you only once set your tileset-texture and lock your vertexbuffer, even though you fill up your whole screen with tiles.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!