Note that there are some explanatory texts on larger screens.

plurals
  1. POHow would I efficiently make fake tile shadows?
    text
    copied!<p>So I'm making a tile based game and I'd like to add some fake shadows to the tiles. It's kinda hard to explain so I'll do it with pictures:</p> <p>Let's say this is my tile world:</p> <p><img src="https://i.stack.imgur.com/aqcMu.png" alt="world"></p> <p>And I want it to have shadows like this:</p> <p><img src="https://i.stack.imgur.com/Ssaka.png" alt="shadows"></p> <p>Because the world is tile based, I can split all the shadow parts into separate images:</p> <p><img src="https://i.stack.imgur.com/keOhr.png" alt="parts"></p> <p>But now I have no idea how I would bring this to code. Well, actually I do have ideas, but they're incredible tedious and they don't work optimally.</p> <p>I've tried a massive if-statement...</p> <pre><code>bool ul = adjacentBlocks[0, 0] == Block.Type.Rock; //Upper Left bool um = adjacentBlocks[1, 0] == Block.Type.Rock; //Upper Middle bool ur = adjacentBlocks[2, 0] == Block.Type.Rock; //Upper Right bool ml = adjacentBlocks[0, 1] == Block.Type.Rock; //Center Left //bool cm = adjacentBlocks[1, 1] == Block.Type.Rock; //CURRENT BLOCK - NOT NEEDED bool mr = adjacentBlocks[2, 1] == Block.Type.Rock; //Center Right bool ll = adjacentBlocks[0, 2] == Block.Type.Rock; //Lower Left bool lm = adjacentBlocks[1, 2] == Block.Type.Rock; //Lower Middle bool lr = adjacentBlocks[2, 2] == Block.Type.Rock; //Lower Right if (ml) { texture = "Horizontal"; flipX = false; flipY = false; } if (mr) { texture = "Horizontal"; flipX = true; flipY = false; } if (um) { texture = "Vertical"; flipX = false; flipY = false; } if (lm) { texture = "Vertical"; flipX = false; flipY = true; } if (ml &amp;&amp; ul &amp;&amp; um) texture = "HorizontalVertical"; //More if statements I can't be bothered to write if (ul &amp;&amp; um &amp;&amp; ur &amp;&amp; ml &amp;&amp; mr &amp;&amp; ll &amp;&amp; lm &amp; lr) texture = "Full"; </code></pre> <p>And a massive lookup table...</p> <pre><code>var table = new List&lt;TextureBlockLayout&gt; { new TextureBlockLayout("Horizontal", false, false, new[,] { { true, true, false }, { true, true, false }, { true, true, false } }), new TextureBlockLayout("Horizontal", true, false, new[,] { { false, true, true }, { false, true, true }, { false, true, true } }), new TextureBlockLayout("Full", false, false, new[,] { { true, true, true }, { true, true, true }, { true, true, true } }) }; </code></pre> <p>But either I'm doing something wrong or they just refuse to work at all. Any ideas?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload