I've been working on a Tile Map that is working and displays the tiles on screen according to the associated number in the array.
Tile 0 is for Grass, 1 is for water and 2 is for Coins. When the user is clicking the coins tile I need it opens a menu that the user can click a button to 'TAKE COINS' from the tile.
var myMap: Array = [
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 2, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 2, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 2, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 1, 0, 0, 0]
];
for (var i: int = 0; i < mapHeight; i++) {
for (var u: int = 0; u < mapWidth; u++) {
var tile: MovieClip = new Tile();
tile.gotoAndStop(myMap[i][u] + 1);
tile.x = tileSize * u
tile.y = tileSize * i
tile.theIDi = i;
tile.theIDu = u;
tile.buttonMode = true;
addChildAt(tile, 0);
tile.addEventListener(MouseEvent.CLICK, clickTile);
}
}
function clickTile(event: MouseEvent) {
positionX = event.currentTarget.theIDu;
positionY = event.currentTarget.theIDi;
if(myMap[positionX][positionY] == 2) {
openGoldMenu(positionX, positionY);
}
}
function openGoldMenu() {
takeCoinsMenu.x = 100;
takeCoinsMenu.y = 200;
buttonTake.addEventListener(MouseEvent.CLICK, takeCoins);
}
function takeCoins(event: MouseEvent) {
myStats[0].gold = myStats[0].gold + 10;
WHAT TO WRITE HERE? HOW CAN I ACCESS THE CURRENT TILE THAT WAS CLICKED WITH THE GOLD COIN ON? URGH CONFUSED!
}