Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8192905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:17:53+00:00 2026-06-07T04:17:53+00:00

So I’m making a tile based game and I’d like to add some fake

  • 0

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:

Let’s say this is my tile world:

world

And I want it to have shadows like this:

shadows

Because the world is tile based, I can split all the shadow parts into separate images:

parts

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.

I’ve tried a massive if-statement…

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 && ul && um) texture = "HorizontalVertical";
//More if statements I can't be bothered to write
if (ul && um && ur && ml && mr && ll && lm & lr) texture = "Full";

And a massive lookup table…

var table = new List<TextureBlockLayout>
                                        {
                                            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 }
                                                                                         })
                                        };

But either I’m doing something wrong or they just refuse to work at all. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:17:55+00:00Added an answer on June 7, 2026 at 4:17 am

    Each tile has eight neighbors. Each neighbor has two possible states. Map the states of the neighbors into bits in a byte, and use the byte as an index into a 256-element lookup table.

    Yes, this is the “brute force” solution, and you might be able to get by with a much smaller table using some cleverer approach. But 256 elements isn’t that much (you can easily load it from a data file), and the nice thing about this approach is that it’s completely general — you can have all the 256 tiles look subtly different if you like.


    OK, taking a closer look at the way your example tiles are shaded, it looks like you really only need four bits (and thus a 16-element table):

    1. Set this bit if the north, west and northwest neighbors are all green.
    2. Set this bit if the north, east and northeast neighbors are all green.
    3. Set this bit if the south, west and southwest neighbors are all green.
    4. Set this bit if the south, east and southeast neighbors are all green.

    Even some of these 16 tiles are still rotated / mirrored versions of each other, but it may be easiest to store the orientation in the table alongside the tile index rather than trying to calculate it in the code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.