Dynamic Z-Order with many static objects

0 favourites
  • 7 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • Hi,

    I'm trying to make a game with a perspective like the old RPGs.

    If the Playersprite (or any NPCs sprite, moving objects like flying arrows...) is in front of a tree, it should be in front of it on the z-order. Is the Player behind the tree its Z-Order should be behind.

    Actually this is no problem with this piece of code:

    But if the Player decides to build a castle out of many walls, surrounded by many trees with lots of static objects around (around 1000 objects on screen might happen), this code uses a lot of horsepower to rearrange the Z-order every tick.

    I made a small example here: https://drive.google.com/file/d/0B0hkmULXH76qTnFzaDlVWTllU3c/view?usp=sharing

    If you press space, new trees will spawn. If you make enough in Debugmode you can see it uses way to much ressources for just rearranging the order.

    Now my question: Is there a way to keep the Z-order of the static objects (like trees and walls) and just rearrange the Z-order of moving things?

    I aready tried to create a pixel for every y-coordinate on screen which is in the z-order-family and everything that moves is set in front of the pixel with the same y-coordinate. But somehow it didn't work very well - even spawning a pixel for every y-coordinate on start of layout takes ages on larger layouts.

    If there would be a way to pick the next object with a higher or lower y-coordinate on Layout, I would set the moving object behind or in front of it...

    So far my thoughts about the problem. If you have ideas, feel free to tell me, i'd appreciate it.

  • why you didn't use layer?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I use layer but I don't understand how it would help here. Since the tree somtimes must be in front of an object and sometimes behind, I would need a layer for every object (or every y-coordinate)...

  • thank you Blackhornet, but this is exactly what I'm already doing, as shown in the second screenshot and in my example (I hope those links work). And since I need to do it for all objects - static an moving, it takes to much power...

  • After a while of trial and error I found a way to pick the next object above a moving object:

    (by picking all with a smaller y-coordinate and then picking the topmost object of them and then placing the moving object in front of the picked one). It works fine, but unfortunately it consumes more CPU to find this topmost object out of 1000 then rearranging the whole ZOrder. So it doesn't really help. My best solution so far is: doing rearrange Zorder every 1/20 seconds. So it consumes just 1/4 of my CPU power, but this solution seems a bit shabby. If anybody knows something better, please let me know.

  • dayle85 I also have the same performance problem and i bought the Q3D plugin just to test the performance. A test you can do and maybe help your game is to check for collision with the upper part of the trees and move them to another layer or zorder till the collision stops. Here is the concept, needs work but you get the idea https://dl.dropboxusercontent.com/u/120 ... Test2.capx

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