Game/Source/Map.cpp
// Create the definition for a function that loads a single layer
Create the definition for a function that loads a single layer
Create the definition for a function that loads a single layer
bool Map::LoadLayer(pugi::xml_node& node, MapLayer* layer)
{
	bool ret = true;
	layer->name = node.attribute("name").as_string();
	layer->width = node.attribute("width").as_int();
	layer->height = node.attribute("height").as_int();
	pugi::xml_node layerData = node.child("data");
	if (layerData == NULL)
	{
		LOG("Error with XML file.");
		ret = false;
		RELEASE(layer);
	}
	else
	{
		layer->data = new uint[layer->width * layer->height];
		memset(layer->data, 0, layer->width * layer->height);
		pugi::xml_node tile = layerData.child("tile");
		for (int i = 0; tile; ++i)
		{
			layer->data[i] = tile.attribute("gid").as_uint(0);
			tile = tile.next_sibling("tile");
		}
	}
	LoadProperties(node, layer->properties);
	return ret;
}
bool Map :: LoadLayer ( pugi :: xml_node & node , MapLayer * layer ) { bool ret = true ; layer -> name = node . attribute ( " " ) . as_string ( ) ; layer -> width = node . attribute ( " " ) . as_int ( ) ; layer -> height = node . attribute ( " " ) . as_int ( ) ; pugi :: xml_node layerData = node . child ( " " ) ; if ( layerData == NULL ) { LOG ( " " ) ; ret = false ; RELEASE ( layer ) ; } else { layer -> data = new uint [ layer -> width * layer -> height ] ; memset ( layer -> data , 0 , layer -> width * layer -> height ) ; pugi :: xml_node tile = layerData . child ( " " ) ; for ( int i = 0 ; tile ; ++ i ) { layer -> data [ i ] = tile . attribute ( " " ) . as_uint ( 0 ) ; tile = tile . next_sibling ( " " ) ; } } LoadProperties ( node , layer -> properties ) ; return ret ; }
Create the definition for a function that loads a single layer
Create the definition for a function that loads a single layer
// Load layer properties