tileW = 50;
tileH = 50;
var map:Array = [ [3, 2, 2, 2, 2, 2, 2, 3, 1, 1],
[3, 3, 3, 2, 2, 2, 3, 3, 1, 1],
[1, 1, 3, 3, 3, 3, 3, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 4, 4, 4, 4],
[1, 4, 4, 4, 4, 4, 4, 4, 4, 4],
[4, 4, 4, 4, 2, 2, 4, 4, 4, 4],
[4, 4, 4, 4, 2, 2, 4, 4, 4, 4],
[4, 4, 4, 4, 4, 2, 4, 4, 4, 4],
[1, 1, 1, 4, 4, 2, 4, 4, 1, 1],
[1, 1, 1, 1, 3, 2, 3, 1, 1, 1]
];
function drawMap(map) {
mapH = map.length;
mapW = map[0].length;
num = 0;
attachMovie("tile", "tile", mapH * mapW);
for (i = 0; i < mapW; i++) {
for (j = 0; j < mapH; j++) {
tile.duplicateMovieClip("tile" + num, num);
t = this["tile" + num];
t.gotoAndStop(map[j]*);
//trace(map*[j]);
t._width = tileW;
t._height = tileH;
t._x = tileW * i;
t._y = tileH * j;
num++;
//trace(num);
}
}
tile.removeMovieClip();
}
function checkTile(x, y) {
count = (mapH*mapW)-1;
for (k=0; k<count; k++) {
name = _root["tile"+k];
if (name.hitTest(x,y)) {
return "tile"+k;
}
}
}
drawMap(map);
_root.onMouseMove = function () {
tile = checkTile(_xmouse, _ymouse);
trace(tile);
}
Run of the mill stuff here. Generating a map from a 3d array. Tile based worlds…yada yada yada.
Then we get onto the checkTile function which is a function (as the name implies) that checks the tile that those x and y co-ords are on. To test it I asigned to to the mouse co-ords. And it was all working well, until you hover over the last tile (bottom left) which should be tile99, but comes up in my output window as undefined…umm, what the hell?
.fla attached (flash 8 as the forum suggests)
P.S. Not too keen on these new code colours I have to say…