...

View Full Version : Tile-Based Engine - Question on Theory



Shirk Deio
05-26-2009, 02:29 AM
I have a non-specific question, more about the theory of tile-based engines than the actual coding.

What do you think would be the best way to treat objects larger than the tile size? For example, a tree that is taller than the bounds of the tile, or a gate that swings open past the side of the tile's width, or a gigantic boulder that is taller and wider than the tile? How should they be handled, stored, and loadeD?

CodeSpawn
05-26-2009, 09:28 PM
Well. What about doing something like treating them as a combination of tiles? Like 6 tiles instead of one.

Shirk Deio
05-26-2009, 11:14 PM
But how do I relate that to things such as the scrolling of a screen using a gotoAndStop engine?

333qaz333
06-04-2009, 12:30 AM
Hmm. Well, there are many ways to accomplish that, and I guess the "best" way would just be a matter of opinion. I guess what I would do is this:
I would attach my tiles through a multi-dimensional array, like:


map_array = new Array();
map_array = [[1,1,1,1,1,1],
[1,0,0,0,0,1],
[1,0,0,0,0,1],
[1,0,0,0,0,1],
[1,0,0,0,0,1],
[1,1,1,1,1,1]];

Then, I would attach the movieclips to the stage, dynamically, using nested for loops. So I would attach tile one (probably a solid wall..) to the stage when my array says 1... etc... etc...

Okay, so once you've got your basic tiles down, now I would think about how to attach my items, such as a big 6-tile boulder or whatever.

So I would do something like:


items_array = new Array();
items_array = [["boulder", 2, 3], ["tree", 5, 4]]; //[frame, xtile, ytile]


So then you can loop through this array, and attach these movie clips separately (making sure that the item's layers are above the tile's layers, of course).


So.. I guess that that would be how I would approach that situation. But again, I don't think that there is any right or wrong answer here, I think it just depends on how you like coding.

pranavnegandhi
06-09-2009, 11:41 AM
I had worked on a simple tile-map editor in another era on Macromedia Director, so I have some practical experience to shed upon this.

Tiles themselves are to granular to be useful once you start building large games. You have to move on to the next level, probably calling them objects. These are game-specific bits of code which 'understand' what they are representing and have methods to manipulate them accordingly. E.g. you have a tree object which might have a Grow method. In its initial stage, it only occupies a single tile. But once you call Grow() upon it, it starts increasing in height (and number of tiles) and sends this updated list to your main map renderer object. A gate object might have Open() and Close() methods which change the state of the object.

Other than this, you also need to have an opacity map. The player cannot pass through opaque objects while it can pass through transparent ones. I had implemented a 2-bit opacity (on or off), but you can take this to another level and make some things more or less opaque, thus affecting the speed or effort required to pass through them. This too can be handled at the object level, making it much easier than it might be if you were working with tiles directly.

HTH.

.p

Shirk Deio
06-12-2009, 01:57 PM
Okay, so once you've got your basic tiles down, now I would think about how to attach my items, such as a big 6-tile boulder or whatever.

So I would do something like:


items_array = new Array();
items_array = [["boulder", 2, 3], ["tree", 5, 4]]; //[frame, xtile, ytile]



Ah, that makes sense! Treat the larger objects not as tiles, but as objects on top of the tiles. That's perfect, thanks for the help!

333qaz333
06-13-2009, 02:25 AM
Haha, no problem. I have done a ton of tile-based games.. so I know quite a bit about them. So any other questions, just ask and I'll (we'll) be glad to help you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum