Understanding Map Data

As you open the json file of the map on the data folder on your game. You will see "data" array with so so so so many integers. Those are the fundamentals of the map.

****Requirements****
Before you start understanding the array structure of the map, you need the ff first.
  • Basic JavaScript Understanding
  • What is Array?
  • Difference of $dataMap vs $gameMap

This will help you to build/create a map manipulating or related plugin.
--------------------------------------------------------------------------------------------------

****Examples****

Lets use this map as example.
index.php

****Map Layers****

There are 6 layers on the map.
  1. Ground layer. Which are the green ground once on the sample map.
  2. Bush layer. Which is the grass on sample map.
  3. Design Layer 1. Basically a design tile.
  4. Design Layer 2. Basically a design tile.
  5. Shadow Layer. When you use shadow pen, this part of the array will be filled.
  6. Region ids. Well... regions ids.
Let me show you using an image.
index.php


****Coding and
Logic****

How to access or change it?
by using simple multiplication function.
-----------Getting value-----------------
var getMapData = function(x,y,z){
var pY = y * $dataMap.height;
var pZ = z *( $dataMap.height * $dataMap.width);
var pX = x;
return $dataMap.data[(pY + pX + pZ)];
​
};
------------------------------------------
x: must be within width range of the map.
y: must be within height range of the map.
z: 0 to 5. Which represents layers of the map.

Usage Example: base on the sample map/array
  • getMapData(0,0,1); This will return 3046 on bush layer.
  • getMapData(8,8,5); This will return 1 on region layer. (last value)

-----------Change value-----------------
var changeMapData = function(x,y,z,v){
var pY = y * $dataMap.height;
var pZ = z *( $dataMap.height * $dataMap.width);
var pX = x;
$dataMap.data[(pY + pX + pZ)] = v;
​
};
------------------------------------------
x: must be within width range of the map.
y: must be within height range of the map.
z: 0 to 5. Which represents layers of the map.

Usage Example: base on the sample map/array
  • changeMapData(0,0,1,5016); This will change 3046 to 5016 on bush layer.
  • changeMapData(8,8,5,255); This will change 1 to 255 on region layer. (last value)
Combined function
-----------Change/Get value-----------------
var actionMapData= function(x,y,z,v){
var pY = y * $dataMap.height;
var pZ = z *( $dataMap.height * $dataMap.width);
var pX = x;
if (v){
$dataMap.data[(pY + pX + pZ)] = v;
}else{
return $dataMap.data[(pY + pX + pZ)];
}
​
};
------------------------------------------


****
Understanding Shadow Byte****

To be continued...
Thanks! Tried to decipher that for a long time, but could not do it in the end... I would still welcome information as to how the tiles are drawn in regards to tileset values (for example the ground tiles, why the values are as they are)
Thanks! Tried to decipher that for a long time, but could not do it in the end... I would still welcome information as to how the tiles are drawn in regards to tileset values (for example the ground tiles, why the values are as they are)
Hello! I will tackle this one after the shadow byte section. 🙂 Thank you
Sure thing, take your time. 🙂
Are you sure about the shadow layer? That would indicate that shadows are always shown on top of other graphics, but at least in Ace, if you put a pile of wood beside a building, the shadow would be under the wood, not over it. And MV was very largely based on Ace logic.
Thanks is awesome! I just implemented some code to randomly move an event to a random tile coordinates based on region. I will use this for random, but purposeful placement of treasures. But it will be great for bad guys, too.

One note is that after I grabbed the $dataMap info, I stored the region array using the following code:
var regionLocation = {region: tileRegion, x: tileX, y: tileY};

But when I read my variable tileY I needed to do
regionLocation.y / $dataMap.width
in order to get the proper y-coordinate. Maybe that will help someone else?

Where do I find the Understanding Shadow Byte article? I can't find it.

Original thread: https://forums.rpgmakerweb.com/threads/understanding-map-data.83140/