Sign in to follow this  
Crazyfool

D3D9 Map Drawing

Recommended Posts

Hi, I have made two seperate posts in For Beginners (about 4 days apart) and both were unanswered, so I figure I'll post here and see if it gets any response. I've been working a 2d tile map engine for a bit, and started adding to my test map to the point of being 250x250 tiles, and needless to say, drawing all those tiles was starting to wear down on the processor (not when zoomed in, but when zooming out). So I started to work on something where it only drew things in an height x width rectangle (viewable screen) of the camera. Ok, so kind of got it to work, but when I move my camera around, it seems to move faster then the rectangle being drawn. Ok, so this is how it is when the program start, where the * is the camera.
 ________________________
|                        |
|                        |
|                        |
|                        |
|           *            |
|                        |
|                        |
|________________________|
Ok, so this is how it is after maybe 10 seconds of going right.
 ________________________
|                        |
|                        |
|                        |
|                        |
|                    *   |
|                        |
|                        |
|________________________|
I know that the square (map) is changing, and the camera seems to just be moving faster. here's my code:
for(int x = camera.vLookAtPt.x + 11; x > camera.vLookAtPt.x - 11; x--)
	{
		if(abs(x) < map->width)
		{
			for(int z = camera.vLookAtPt.z - 11; z < camera.vLookAtPt.z + 11; z++)
			{
				if(abs(z) < map->height)
				{
					d3ddev->SetTexture(0, textures[map->tiles[abs(x)][abs(z)]]);

					D3DXMatrixTranslation(&matTranslate, x * 0.8, 0.0f, z * 0.8);
					d3ddev->SetTransform(D3DTS_WORLD, &(matTranslate));
					d3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
				}
			}
		}
	}

That is the relevant (I think) part of my draw map code. I dont know what is causing this problem because the camera just drifts farther and farther away.

Share this post


Link to post
Share on other sites

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