I decided to fill the gap in the paper 2d Plugin, it lacked the ability to quickly and easily create maps. So I took it upon myself to do the required research and integrate an auto tiling system through bit masking patterns. After research, I choose to implement the pattern used by the most popular 2D RPG engine, RPGMaker.
![](https://static.wixstatic.com/media/da9d9c_c38245c119b4464eb2c6b610d7538e92~mv2.jpg/v1/fill/w_980,h_551,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/da9d9c_c38245c119b4464eb2c6b610d7538e92~mv2.jpg)
Image from RPGMaker forum, same pattern used in the Tiling System i built
I choose to support different tile types and eight directional auto tiling to get a much more accurate and nicer looking result from the auto tiling system.
![](https://static.wixstatic.com/media/da9d9c_a1504241602a4bdd9e3acf1efb2bde6d~mv2.png/v1/fill/w_532,h_227,al_c,q_85,enc_auto/da9d9c_a1504241602a4bdd9e3acf1efb2bde6d~mv2.png)
Edited images from tutsplus.com by Sonny Bone for visual ref
The example image above show the concept of assigning IDs through bit masks works on four direction.
![](https://static.wixstatic.com/media/da9d9c_58bc7ee401334bed86c04b85850d2b07~mv2.jpg/v1/fill/w_258,h_293,al_c,q_80,enc_auto/da9d9c_58bc7ee401334bed86c04b85850d2b07~mv2.jpg)
The system would follow a ruleset to generate the Tile Group Sets, each sets IDs so that no manual data would have to be entered. You can see above the red markings showing a tile set group and inside, marked with blue, are the tile IDs being cut up.
The patterns that drive these systems can also be driven by a data table to override the default ruleset that says what type of tile cases should use what combination of four sub tiles to create the desired tile.
Auto tiling patterns and types of behaviour to be defined for each tile set.
![](https://static.wixstatic.com/media/da9d9c_d02e716a71f54932948c262085a9627e~mv2.gif)
gif of auto tiling in engine
Challenges
My limited understanding of bit masking and binary made the start pretty rough, but after doing some research and practice, I picked it up pretty fast. The general system for a bit masking were pretty straight forward to implement, the challenges came from building upon the Paper2D editors runtime and editor modules. Keeping it fast and simple while allowing the system to still be configured for different types of patterns(and to not break stuff too).
Few code snippets
// Bitmask for defining the Tile type to assemble
uint8 index = (NorthWest)|(North << 1)|(NorthEast << 2)|(West << 3)|(East << 4)|(SouthWest << 5)|(South << 6)|(SouthEast << 7);
//...
// itterating through surround tiles checking adject tiles
FPaperTileInfo TargetInk = GetTile(TargetLoc.X, TargetLoc.Y, Layer);
// are we valid and not looking at the same tile?
return (GetTile(TargetLoc.X, TargetLoc.Y, Layer).IsValid() && !TargetInk.AutoTileGroupID == InkID);
//...
// painting editor snippet
if ((Ink.IsValid() || bBlitEmptyTiles) && (TargetLayer->GetCell(TargetX, TargetY) != Ink))
{
if (!bChangedSomething)
{
TargetLayer->SetFlags(RF_Transactional);
TargetLayer->Modify();
bChangedSomething = true;
}
if (FindSelectedComponent()->TileMap->AutoTileEnabled)
{
FindSelectedComponent()->AutoTileInkedTile(Ink, TargetX, TargetY, TargetLayer);
}
else
{
OutDirtyRect += FVector(TargetX, TargetY, LayerCoord);
TargetLayer->SetCell(TargetX, TargetY, Ink);
}
//...
Comments