# 2d Scroller - thoughts about tiling

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

## 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 on other sites
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 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.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 24
• 42
• 75