Sign in to follow this  
HorrorVision

Displaying Isometric Maps *solved*

Recommended Posts

EDIT: Ok the problem is solved, i rewrote the code and used another method. new code below, scrolling is smooth, and i think its fast enough. EDIT: I changed the code, so now it shows the real map at least if the m_mapX and m_mapY variables are 0. still the scrolling rips everything :/ Hi guys, im currently working on my first isometric engine, and im really stuck on the drawing stuff, and the more i think, the more errors i put into the code lol. Here's what i have
int IsoMap::Render(void)
{
	for (int n = 0; n < m_mapDimension.GetX() * m_mapDimension.GetY(); n ++)
	{
		if (m_map[n].GetValid())
		{
			IntPoint tilePoint = GetScreenPosition (n);
			tilePoint.SetX (tilePoint.GetX() - m_screenPosition.GetX());
			tilePoint.SetY (tilePoint.GetY() - m_screenPosition.GetY());

			if (m_viewRect.PointInRect (tilePoint.GetX(), tilePoint.GetY()) || 
				m_viewRect.PointInRect (tilePoint.GetX() + m_tileDimension.GetX(), tilePoint.GetY()) ||
				m_viewRect.PointInRect (tilePoint.GetX(), tilePoint.GetY() + m_tileDimension.GetY()) ||
				m_viewRect.PointInRect (tilePoint.GetX() + m_tileDimension.GetX(), tilePoint.GetY() + m_tileDimension.GetY()))
			{
				IsoTilesetSprite* cell = m_map [n].GetSprite ();

				cell->m_sprite->SetPosition (tilePoint.GetX(), tilePoint.GetY());
				cell->m_sprite->Render ();
			}
		}
	}
   	
	return TRUE;
}

IntPoint IsoMap::GetScreenPosition(int a_index)
{
	IntPoint screenPos;
	if (a_index > m_mapDimension.GetX() * m_mapDimension.GetY())
		return screenPos;
	
	int my = (a_index / (m_mapDimension.GetX()));
	int mx = a_index - (my * (m_mapDimension.GetX()));

	screenPos.SetX ((mx * (m_tileDimension.GetX() / 2)) - 
		(my * (m_tileDimension.GetX() / 2)));

	screenPos.SetY ((my * (m_tileDimension.GetY() / 2)) + 
		(mx * (m_tileDimension.GetY() / 2)));

	return screenPos;
}

m_mapX and m_mapY are the current positions of the map, starting with 0, they increase/decrease with a scroll function, both are float [Edited by - HorrorVision on June 9, 2007 8:48:51 AM]

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