Page 1 of 1

How to use negate function in TextureMap?

Posted: Fri Sep 27, 2013 3:48 am
by zaquanishak
Hi,
I see from the comment in IgeTextureMap from the function negate, it state that this function will take another map and removes any data from this map where data already exits.

Code: Select all

/**
	 * Takes another map and removes any data from this map where data already
	 * exists in the other.
	 * @param {IgeTileMap2d} entity The other map to read map data from.
	 * @return {*}
	 */
	negate: function (entity) {
		if (entity !== undefined) {
			var x, y,
				entityMapData = entity.map._mapData,
				thisMapData = this.map._mapData;

			for (y in entityMapData) {
				if (entityMapData.hasOwnProperty(y)) {
					for (x in entityMapData[y]) {
						if (entityMapData[y].hasOwnProperty(x)) {
							if (thisMapData[y] && thisMapData[y][x]) {
								// This map has data in the same place as the passed
								// entity's map so remove this map's data
								delete thisMapData[y][x];
							}
						}
					}
				}
			}
		}

		return this;
	},
what i try to achieve here is to load and unload multiple map. So my question how do i use this function to load another map and removes any data from this map?

Regards,
Zachz

Re: How to use negate function in TextureMap?

Posted: Fri Sep 27, 2013 9:36 pm
by coolbloke1324
zaquanishak wrote:Hi,
I see from the comment in IgeTextureMap from the function negate, it state that this function will take another map and removes any data from this map where data already exits.

Code: Select all

/**
	 * Takes another map and removes any data from this map where data already
	 * exists in the other.
	 * @param {IgeTileMap2d} entity The other map to read map data from.
	 * @return {*}
	 */
	negate: function (entity) {
		if (entity !== undefined) {
			var x, y,
				entityMapData = entity.map._mapData,
				thisMapData = this.map._mapData;

			for (y in entityMapData) {
				if (entityMapData.hasOwnProperty(y)) {
					for (x in entityMapData[y]) {
						if (entityMapData[y].hasOwnProperty(x)) {
							if (thisMapData[y] && thisMapData[y][x]) {
								// This map has data in the same place as the passed
								// entity's map so remove this map's data
								delete thisMapData[y][x];
							}
						}
					}
				}
			}
		}

		return this;
	},
what i try to achieve here is to load and unload multiple map. So my question how do i use this function to load another map and removes any data from this map?

Regards,
Zachz
The negate method is not designed for removing data from a map and replacing it with data from another map.

The easiest way to load a new map is just to create a parent entity that you mount all your map layers to then remove that parent when you want to remove the map.

You can then create a new parent and mount the new map's layers to it.