In games like Factorio, you might notice that when the player is at a certain coordinate relative to the tree, it renders in front of the player, thereby giving the effect that the player is behind the tree. My question is, how is this accomplished?

Here are some examples: Behind a telephone pole: enter image description here In front of one: enter image description here

  • \$\begingroup\$ Sure. One min and I'll add them. \$\endgroup\$ – Zimri Leisher Dec 28 '16 at 15:06

This effect is usually accomplished through sorting the draw order along an axis. In this case, the Y axis. Objects with the lower Y value (higher up on the screen) are drawn first. Objects drawn with a higher Y value are then drawn, overlapping the objects drawn earlier.

Image of draw sorting

In this example, the X value is unimportant;

On the left, the orange box is drawn first because it's y is less than the y of the green box.

On the right, the orange box has now moved down 10 units on the y axis and is now drawn after the green box because it's y is greater than that of the green box.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.