I was playing about with layers yesterday, I was getting some extremely odd results, to the point that my nut was so well and truly mangled I decided never to touch them again, and went back to simple ordered drawing.
I have a sprite of a car body, just the body. Then I have other sprites for the lights, I draw the lights in the same position as the body sprite, so I can turn on indicators, front, brake, reversing lights without having to create a graphic for every single combination. This approach was the only one that made any sense to me.
Now, the drawing routine was setup to to draw Front to Back, so layer 0.0 would be the back, and 1.0 would be foremost. I built up the scene as you would expect, background, car, hedges, bridges, trees etc, all in the logical order. This was fine, however, when I turned on any lights of the car the color of my car body changed, not dramatically, but it got lighter. I tried putting the lights on a different layer, so the car was on 0.2 and the lights were on 0.3, still the same. My car body also changed colour at certain points in the world without any reason, but in repeatable places. During testing I tried setting up a trigger location, so when the car was within certain screen positions a different sprite would be drawn, the car body changed color. This wasn’t on the same layer!
The reason for wanting layers was so I could change the car layer so it could run over and under certain parts of the 2d world. This is where the next strange behaviour was noticed. If I moved the car from 0.2/0.3 to 0.5/0.6 items on layer 0.1 started drawing in a different order. I honestly thought I was going bonkers. I tried all sorts of different combinations but no matter what I tried I couldn’t get around the car body changing color when the lights were turned on. I’m sure you’d be quite alarmed if every time you put your foot on your brake pedal your car changed color, or when you turned on indicators the whole care flashed! This wasn’t an acceptable situation.
So, layers. What’s going on?