Jump to content
  • Advertisement
Sign in to follow this  

layer movement

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

can someone PLEASE tell me what's wrong with this function??? it's really irritating...
[source language=cpp]
void cTextureLayer::DrawLayer()
	if (m_bVisible == false)

	unsigned short Data;
	long RectX, RectY; // Stores the Rect X and Y
	long TileX, TileXBeg, TileY; // Stores which tile it's rendering
	long WinX, WinY;   // Stores where on the screen it's rendering
	float OffX, OffY;
	RECT Rect;

	Pos.z = m_Pos.z;

	if (m_Pos.World == false) ZeroMemory(&Cam, sizeof(D3DXVECTOR3));
	else {
		Cam.x = W_Graphics.GetCamX();
		Cam.y = W_Graphics.GetCamY();
	// Get tile and offset
	if (m_Pos.x < 0.0f)
		TileX = TileXBeg = (long)ceil(m_lFrameWidth / (m_Pos.x * -1));
		OffX = fmodf((float)m_lFrameWidth,(m_Pos.x * -1));
	} else {
		TileX  = TileXBeg = 0;
		if (m_Pos.x > 0) OffX = fmodf((float)m_lFrameWidth, m_Pos.x);
		else OffX = 0.0f;

	if (m_Pos.y < 0.0f)
		TileY = (long)ceil(m_lFrameHeight / (m_Pos.y * -1));
		OffY = fmodf((float)m_lFrameHeight, (m_Pos.y * -1));
	} else {
		TileY = 0;
		if (m_Pos.y > 0.0f) OffY = fmodf((float)m_lFrameHeight, m_Pos.y);
		else OffY = 0.0f;

	// Clipping
//	if (m_Pos.x + (m_lFrameWidth * m_lLayerCol) > 0 &&
//		TileX < m_lLayerCol &&
//		m_Pos.y + (m_lFrameHeight * m_lLayerRow) > 0 &&
//		TileY < m_lLayerRow)
//	{
		for (WinX=WinY=0 ; WinY < m_lWindowRow && TileY < m_lLayerRow || Pos.y > W_Graphics.GetBufferHeight() ; WinX++)
			Data = m_Data[TileX][TileY];
			RectX = (long)((Data % m_sTexCol) * m_lFrameWidth);
			RectY = (long)(floor(Data / m_sTexCol)) * m_lFrameHeight;
			SetRect(&Rect, RectX, RectY, 
				RectX + m_lFrameWidth, RectY + m_lFrameHeight);
			Pos.x = (float)((WinX * m_lFrameWidth) - OffX);
			//if (m_Pos.x > 0) Pos.x += (m_Pos.x * -1) * m_lFrameWidth;  // incase layer is too far right
			Pos.y = (float)((WinY * m_lFrameHeight) - OffY);
			//if (m_Pos.y > 0) Pos.y += (m_Pos.y * -1) * m_lFrameHeight; // incase layer is too far down
				D3DCOLOR_ARGB(m_cAlpha, m_cRed, m_cGreen, m_cBlue)
			if (TileX > m_lWindowCol || TileX > m_lLayerCol || Pos.x > W_Graphics.GetBufferWidth())
				TileX = TileXBeg;
				WinX = -1;
//	}

The arrow keys increase and decrease the x and y values for the layer. It's a tile based layer and gets it data from short** m_Data. There is then a .png file the it extracts each of the tiles from and draws them onto the screen. I want to have a global position (m_Pos) and be able to draw the layer where ever it's at and be able to move it around... but there's too much stuff wrong with it and i'm using all the right formulas and i checked my math over and over, i can't seem to find what it's doing wrong....

Share this post

Link to post
Share on other sites
well, i'm supposed to get the whole layer with all the tiles drawn correctly. it's starts off at 0,0 and it's fine, but when i try to move it, it's really glitchy and jumps alot and sometimes it says something about the Data...

Share this post

Link to post
Share on other sites
Eh, sorry. I'm not so good at reading code. To me, the offset calculations look a little off. Usually they're done with a floor/mod pair and factor*tile+offset since modulo/integer arithmetic works that way. But, since you said you checked the math, that's perhaps not it.

I'd also look at the array indexes/bounds, especially if you're getting Data messages.

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!