It sounds like you want to use Tile Bitmasking. Here is a link of a solution, it may be of help to you.