# Tile Based Games

**URL:** <https://forum.kirupa.com/t/tile-based-games/17414>\
**Category:** programming\
**Created:** [April 4, 2003, 9:47pm UTC](https://forum.kirupa.com/t/tile-based-games/17414 "2003-04-04T21:47:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![BullDog\_Flash](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@BullDog\_Flash](https://forum.kirupa.com/u/BullDog_Flash)\
**Post date:** [April 4, 2003, 9:47pm UTC](https://forum.kirupa.com/t/tile-based-games/17414/1 "2003-04-04T21:47:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 4, 2003, 10:21pm UTC](https://forum.kirupa.com/t/tile-based-games/17414/2 "2003-04-04T22:21:06Z")

</div>

[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:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 4, 2003, 10:50pm UTC](https://forum.kirupa.com/t/tile-based-games/17414/3 "2003-04-04T22:50:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 4, 2003, 10:55pm UTC](https://forum.kirupa.com/t/tile-based-games/17414/4 "2003-04-04T22:55:48Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 4, 2003, 10:58pm UTC](https://forum.kirupa.com/t/tile-based-games/17414/5 "2003-04-04T22:58:31Z")

</div>

Well i got the code at  
outsideofsociety

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 5, 2003, 12:20am UTC](https://forum.kirupa.com/t/tile-based-games/17414/6 "2003-04-05T00:20:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 5, 2003, 3:04am UTC](https://forum.kirupa.com/t/tile-based-games/17414/7 "2003-04-05T03:04:02Z")

</div>

Found the Problem.

Its the way you setup the tiles.

I had them way off in the Tile MC.
