How to use negate function in TextureMap?

All things HTML5 or text based engines, or really any web based engines.
Post Reply
zaquanishak
Posts: 53
Joined: Mon Aug 26, 2013 1:54 am

How to use negate function in TextureMap?

Post 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
zachz
Programmer
compass-interactive
User avatar
coolbloke1324
Posts: 181
Joined: Mon Jan 23, 2012 5:20 pm

Re: How to use negate function in TextureMap?

Post 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.
CEO & Lead Developer
Irrelon Software Limited
http://www.isogenicengine.com
Post Reply

Return to “HTML5/Web Engines”