Tile Based Games

Yeah!!!

There great I love the way you make map Arrays.

But I need some help since the site I am using donsent explain this code to well.

[AS]var mapWidth = map[0].length;
var mapHeight = map.length;
for (var i = 0; i < mapHeight; ++i) {
for (var j = 0; j < mapWidth; ++j) {
this.attachMovie(“tile”, “t_”+i+""+j, ++d);
this["t
"+i+""+j].x = (j*tileW);
this["t
"+i+"
"+j].y = (i*tileH);
this["t
"+i+"_"+j].gotoAndStop(map*[j]+1);
}
}
}[/AS]

I have no clue what that does.

Please Please Please tell me what that does i kno its very important to know what it is.

Please anyone please tell me what it does

[AS]
var mapWidth = map[0].length;
var mapHeight = map.length;
for (var i = 0; i < mapHeight; ++i)
{
for (var j = 0; j < mapWidth; ++j)
{
this.attachMovie(“tile”, “t_”+i+""+j, ++d);
this["t
"+i+""+j].x = (j*tileW);
this["t
"+i+"
"+j].y = (i*tileH);
this["t
"+i+"_"+j].gotoAndStop(map*[j]+1);
}
}
[/AS]

That basically goes through an array and assigns a certain “tile” depending on what the value of the array is…

It’s very outdated though and it’s better to use 2 dimensional arrays instead of the method presented… ++i and ++j… Sloppy coding…

playamarz ;player:

Wow Is it possable you could show me a new piece of code to replace that.

If I had the time or effort to I would… But I’m not feeling creative right now…

Just use that piece of code for now… You’ll be fine.

playamarz :beam:

Well i got the code at
outsideofsociety

I have been trying forever to figure out why my character goes off the tiles.

Heres the code

var downY = Math.floor((_y+(_height/2))/_parent.tileH);
var upY = Math.floor((_y-(_height/2))/_parent.tileH);
var leftX = Math.floor((_x-(_width/2))/_parent.tileW);
var rightX = Math.floor((_x+(_width/2))/_parent.tileW);
var centerX = Math.floor(_x/_parent.tileW);
var centerY = Math.floor(_y/_parent.tileH);

I dont know why but my character still goes off the tiles.

I have been mega studying this code and its a shame t dont work well.

Eample in Attachment

Found the Problem.

Its the way you setup the tiles.

I had them way off in the Tile MC.