[MENTION=88462]chiburunga[/MENTION] - That would work as well, but only some of the time. Imagine you have the ground being a solid color and the sky is that same color. Say you did replace them both based on their Y coordinates so that the sky is blue, and the ground is brown. Now imagine the player falls into a pit, and the screen scrolls down too. Eventually the "ground" tiles scroll up to the top of the screen (imagine the walls of the pit take up the full vertical length of the screen). Some of the topmost "ground" tiles would accidentally be replaced with "sky" tiles, even though in the game you're in a pit, away from the sky.
The best solution I've come up with yet works like this:
The emulator chooses one tile to act as a sort of "anchor". It looks at the "anchor", then if any tiles above, below, left, or right of it match a solid color (gray in this example), it replaces them accordingly. You'd be able to specify which tiles above it are for the ground and which tiles below it are for the sky. Left and right seem less useful than up and down, but it's no trouble to implement them all. When a new anchor comes on-screen, then it can switch to something else, so making different graphics for different levels is possible. The tricky thing is making this easy for the user. I don't want them to spend more than a few seconds on it, and no head scratching, screaming at the computer, or pounding on the keyboard