PDA

View Full Version : Tile Based Games



BullDog_Flash
April 4th, 2003, 04:47 PM
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.

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[i][j]+1);
}
}
}

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

Marz
April 4th, 2003, 05:21 PM
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[i][j]+1);
}
}


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:

BullDog_Flash
April 4th, 2003, 05:50 PM
Wow Is it possable you could show me a new piece of code to replace that.

Marz
April 4th, 2003, 05:55 PM
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:

BullDog_Flash
April 4th, 2003, 05:58 PM
Well i got the code at
outsideofsociety

BullDog_Flash
April 4th, 2003, 07:20 PM
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

BullDog_Flash
April 4th, 2003, 10:04 PM
Found the Problem.

Its the way you setup the tiles.

I had them way off in the Tile MC.