Dynamic Z-Order with many static objects

Get help using Construct 2

Post » Sun Apr 19, 2015 1:03 pm

Hi,
I'm trying to make a game with a perspective like the old RPGs.
Image
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:
Image
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.
Last edited by dayle85 on Sat Apr 25, 2015 11:25 am, edited 2 times in total.
B
19
S
1
Posts: 5
Reputation: 1,488

Post » Sun Apr 19, 2015 1:09 pm

why you didn't use layer?
"If you want to move a mountain tomorrow, you should start by lifting stones today."
B
62
S
14
G
2
Posts: 287
Reputation: 6,608

Post » Sun Apr 19, 2015 4:59 pm

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)...
B
19
S
1
Posts: 5
Reputation: 1,488

Post » Sun Apr 19, 2015 5:24 pm

ImageImageImage
B
71
S
21
G
229
Posts: 3,686
Reputation: 128,336

Post » Sun Apr 19, 2015 7:27 pm

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...
B
19
S
1
Posts: 5
Reputation: 1,488

Post » Sun Apr 19, 2015 9:43 pm

After a while of trial and error I found a way to pick the next object above a moving object:
Image
(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.
B
19
S
1
Posts: 5
Reputation: 1,488

Post » Sat Apr 25, 2015 5:13 pm

@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
B
35
S
11
G
3
Posts: 97
Reputation: 3,478


Return to How do I....?

Who is online

Users browsing this forum: rayolf, Yahoo [Bot] and 23 guests