Jump to content
  • Advertisement
Sign in to follow this  

Tilemap, smooth scrolling

This topic is 4437 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 understand that you're probably tired of this question ^__^ but here it goes, How can i make my maprender-function as smooth as possible? I'm using direct3d in c#. My tiles are positiontextured quads and they all share the same vertexbuffer. (may be bad?) anyway, this is how i render the map:

if(System.Environment.TickCount - lastFrame >= 10) 
{
	UpdateInput(); 			
	lastFrame = System.Environment.TickCount;
}
			
Camera.Teleport(xScroll,yScroll,0); //translates the viewpoint   
Camera.Process(device);	

for(int m = 0; m<MAPXSIZE; m++)
{
	for(int n = 0; n<MAPYSIZE; n++)
	{
		if(tiles[m,n].Visible)		//draw if it's visible
		{
			device.SetStreamSource( 0, tile.VertexBuffer_, 0);
			device.VertexFormat = CustomVertex.PositionTextured.Format;

			QuadMatrix.Translate(-1f+tiles[m,n].XPos,(1f-tiles[m,n].YPos), 0); //in screen-coordinates
			device.SetTransform(TransformType.World, QuadMatrix);

			device.RenderState.AlphaBlendEnable = true;
			device.RenderState.AlphaTestEnable = true;
			device.RenderState.ReferenceAlpha = cK.ToArgb(); //colorkey for transparency
			device.RenderState.AlphaFunction = Compare.Equal;

			device.SetTexture(0, tile.tileTextures[tiles[m,n].TextureTypeX,tiles[m,n].TileTextureY]); //setting the right texture
			device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2);
		}
	}
}

So, I thought it would be the best to just lock the input so the other things can run as fast as it can. But it doesn't seem to make any differnce.. this is how i update the camerapositions with the keyboard.
private void UpdateInput()  
{   
	DXInput.KeyboardState keys = inputDevice.GetCurrentKeyboardState();   
	if (keys[DXInput.Key.LeftArrow])
	{
	       xScroll-=0.006f;

	}	
}

Share this post


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

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!