This is a feature I needed in my game, so I decided to make an example of it. This uses a surface object as a collision mask in order to gather data about the surroundings of each tile, and changes the animation frame of the tile based on those around it. With this engine, you can just place tiles into your game and it will automatically change to the correct tile so you can have nice looking borders for your games
The engine itself uses bitmasks, which is a fairly simple idea once you understand it. It looks complicated, but it's rather basic. I add the red coefficient of the grid cell to the right of each tile, divided by 255, to give 0 if there is no tile and 1 if there is. Then, I do the same for the cell to the upper right, but I add 2 instead of 1. For the cell directly above, I add 4. As it goes around the tile, I add a doubling amount each time, moving to 8, 16, 32, 64, and eventually 128. This means I can set the animation frame to this value and will always have the proper position data. For frame 50, which is 32+16+2, I can tell that the bottom left, left, and top right cells adjacent to the cell I am looking at have obstacles in them. So frame 50 would leave those sides of the cell open, whilst closing the other ones. Take a look at the example.swf file to see what this is actually accomplishing
If anyone would like a better explanation, just ask and I'll try to be more in-depth. Have fun!
Attachments
Please login to see this link. [size:8pt](666 downloads, build 252)[/size]
Please login to see this link. [size:8pt](1337 downloads, build 252)[/size]