An efficient Z-ordering system for sprites?

0 favourites
  • 4 posts
From the Asset Store
Global plugin that allow for relatively easy and efficient implementation of an in-game inventory system
  • In typical jRPG, 2D view like Zelda, you have a lot of sprites of trees, shrubs, decals, etc that are quite static.

    But then you have the player, monsters, etc that move around and so you have to constantly update their position and determine which sprites go on top or below. ie. When the player is "behind" a tree, it should have the tree sprite on top.

    I know the basic approach that is to compare them on the Y axis, but my concern is if the map is huge, and there's a LOT of objects to compare to, it would be quite CPU intensive and so on mobiles, performance would suffer.

    Is there a more efficient approach?

  • You can reduce the amount to compare somehow. Only sprites on screen would be one example. Another would be only objects overlapping the player or enemies.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • As R0j0 said, I limit it to the viewport. I also only z-sort when the player is moving (which is often, but still). You could potentially get away with z-sorting less often than every single tick, but it depends on how fast-moving your game is.

  • Thanks R0J0hound & C-7

    It's for all the enemy sprites as well as player & squad, running through the forest and fighting fast paced.

    I thought about doing overlapping but those checks are brutal on CPU when there's a lot of objects to check.

    I'll play around with distance checks, pick nearest and LOS in combination with checking every X time rather than every tic. Thanks!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)