0
\$\begingroup\$

How does browserquest handle tiles above an player?

For example:

When the player stands in front of the tree. the player will be displayed on top of the tree.

enter image description here

When the player stands next to the tree, the tree will be displayed on top of the player.

enter image description here

When the player stands behind the tree, the tree will be displayed on top of the player.

enter image description here

How is this possible? If possible give an example in javascript.

\$\endgroup\$
1
  • \$\begingroup\$ The technique is called "depth sorting". The implementation depends on the type of "projection" you chose. Square tiles should be rather simple, whereas it can already get tricky with an isometric view. As of now your question is kinda vague in that regard. \$\endgroup\$ – bummzack Oct 30 '14 at 13:12
2
\$\begingroup\$

Actually, i'm not sure how "browserquest" handles this. But in other 2D topdown-View games, you just have multiple layers of tiles. Mostly 2+.

In this case, the bottom of the tree is on layer 2, which will be drawn second (first layer is the grass underneath), and the top of the tree is on layer n-1, which will be drawn last.

So the drawing-order would be

  • First Layer (tiles on the ground. Like grass,stones,water)
  • Second Layer (tiles drawn on top of the first layer,like objects,stones,trees)
  • Players/entities
  • Third Layer(tiles above players. Like buildings,trees)
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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