Y based z-order request

Discussion and feedback on Construct 2

Post » Sun May 04, 2014 5:20 pm

Hello

I'd like a feature, which enables me to set a family or objects z-index based on its current Y-axis.
Like, every tick, it simply sets the z-order index to its Y-axis integer.

Atm, I am using a single devoted for each loop on one family (Zorder) sorting it by Y, moving all the family objects to the top as it loops, giving me a nice fluid z-ordering of my dynamic and static objects all in 1 go.

However, this thing alone sucks up a roughly ~9% of total cpu power usage on the profiler tab.

Seeing as the rest of the game totals up to ~22%, I consider my z-order method to be a bit hoggish.

I think that having something native in an object, which can simply set its z-order index to its Y-axis number every tick, could save quite some cpu. Perhaps a Z-order behaviour.

This is not the first time I ran into this issue relating to z-ordering, and did not find a better approach, if there is a better method to do z-ordering, I'd love to hear it.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,567

Post » Sun May 04, 2014 5:26 pm

The method you have is fine, just don't run it every tick, run it once when they move.
Image ImageImage
B
169
S
50
G
169
Posts: 8,285
Reputation: 108,214

Post » Sun May 04, 2014 5:58 pm

@newt wrote:The method you have is fine, just don't run it every tick, run it once when they move.


The for each loop runs continously.

I have, atm, just 10 ai's doing pathfinding to reach my character who moves around in an isomteric like enviroment, about 100 trees instances (several frames with different trees) , 200 or so bushes instances (also with frames for different bushes).

the Ais move about all the time, so the loop needs to run more often.

edit:
the zorder boolean check makes sure dead bodies laying around get ommitted.
You do not have the required permissions to view the files attached to this post.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,567

Post » Sun May 04, 2014 6:29 pm

Its a visual effect, so it stands you can filter it down a bit more by using "is on screen".
Image ImageImage
B
169
S
50
G
169
Posts: 8,285
Reputation: 108,214

Post » Sun May 04, 2014 7:42 pm

newt wrote:Its a visual effect, so it stands you can filter it down a bit more by using "is on screen".



When I read it, I thought, brilliant !! :o , felt silly not to have thought of it :oops:

Then, after applying, it gave a ~1% imrpovement, .... when the player stands still :lol: (screen is following player)

I am thinking that an option to continously set a Z index integer, based on an objects Y value, could be a lot faster.
And likely such a feature would only be rendered on the visible on screen elements.

Still thanks for the suggestion @Newt :D
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,567

Post » Sun May 04, 2014 9:45 pm

Checking every tick makes little sense as we barely even register frame changes at 60fps.
Likewise checking every tick while something is moving makes even less, as it only needs to change z order if it gets a new y coordinate.
Image ImageImage
B
169
S
50
G
169
Posts: 8,285
Reputation: 108,214

Post » Sun May 04, 2014 10:34 pm

@newt wrote:Checking every tick makes little sense as we barely even register frame changes at 60fps.
Likewise checking every tick while something is moving makes even less, as it only needs to change z order if it gets a new y coordinate.


Ohw I did not use an event like every tick, but I meant, the for each event, has that green circulair arrow, making it go continously (like every tick if possible :lol: )


As it is, it's intended for the scirra arcade, fullscreen web, and mobile devices.
Here is a quick dev export for html5 web
no audio yet though
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,567

Post » Thu Jun 12, 2014 6:51 pm

So I have been getting my freak on with the multiplayer functionality, and made quite some steps..

Sadly the topic of the post at hand strikes again -,-

I distilled it down to a loop for zordering having lots of the same instances on a layout.
Meaning: a dedicated loop, with lots of instances from the same object, placing all objects at the top, kills performance for me. (yes with on screen)
I think it has to do with the move to top and or move to bottom action being repetitive executed.

I believe with an automated z-index placement derived from the Y position (or X for horizontal based) could save a load of performance here.

I have isometric levels with lots of things making up walls and scenery, these all stuffed in a family with the player object, and loop through it placing everything on top based on a Y based loop order.
The ordering gives a very clean effect when you walk about through layouts being infront and behind objects.

My latest game in the arcade, Skeleton slayer 2 uses this technique, and you can see the effects walking about around trees and what not, looks really pretty and not bad performance. Most of the performance is actually from the zordering :P

BUT BUT BUT ...

I been adapting that version for a multiplayer version, and as soon as the zorder loops runs at the same time the loops updating the multiplayer objects runs, my performance drops dramatically :(

If I run either, the multiplayer loops, or the zordering loops, alone, they run well, but together, unplayable.


So, here is the request again:

Please add a true/false propperty for objects on layouts to set their Zordering based on the Y axis. (descending: lower Y positions are at the top; in effect, the further upward on the layout (lowest Y = on top, highest Y is on bottom)

I am guessing it could greatly improve zordering for isometric games. (as it would no longer require a dedicated loop handling ALL level objects every loop)
You do not have the required permissions to view the files attached to this post.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,567

Post » Thu Jun 12, 2014 10:18 pm

There is a plugin called ''z sorter'' it do what you are looking for and in my opinion it's a very well made plugin with minimal use o CPU
B
32
S
6
G
5
Posts: 437
Reputation: 6,119

Post » Fri Jun 13, 2014 7:00 am

While somewhat hacky,

The way i use layers may be suit your game.

The game i'm making has a base grid of 64x64 px. It's isometric so i have to have a efficient z ordering system.

This only works if all your objects have a base the can be divided by itself. For example units use a base of 1x1, walls 2x2, big buildings 3x3 etc etc.

I translate the layout angle to itself -45, thus giving the feeling of 'isometric'.

So if the base grid is 1x1(*32px), and say the width and the height of the world is 50x50. Then i have 99 layers in game.

For static objects, on.created move to layer int(object.x/32 + object.y/32).

For moving objects, such as player or monsters, for each object, move to layer int(object.x/32,object.y/32)

If your game is using a normal angle, then you can simple add 1 layer per y height / base tile.

So now on create move to layer int(object.y/32) ` same with every tick.

In game this works really well.

However the downside to this is when debugging. The debugger will be checking every layer, so its runs at a crawl.

I hope i explained it well. I can post a screenshot of how it works if you need.

Best of luck,
Tom

For static objects
B
10
S
2
G
1
Posts: 92
Reputation: 926

Next

Return to Construct 2 General

Who is online

Users browsing this forum: Refeuh, SaRaB, tdcostas and 11 guests