Z-ordering won't work?

0 favourites
  • 5 posts
From the Asset Store
_______ Huge collection of metal fixtures ________
  • Hello there!

    I have some text objects that I need to order.

    For every text that I "spawn" I use a function for setting the size, color etc. . And one of these function parameters is z-order, which defaults 50.

    So I have one text. The character name. It should always stay over another text.

    I got it kinda to work this way:

    The name now always is above the other text. But what I find confusing is that it will be the case no matter what I set for the z_order value. Remember z_order defaults 50. I want to sort the objects from 0 to 100, 50 being the average middle. This way I have enough "virtual layers" for placing objects above or below another.

    But no matter what I set the z_order value of the text object, it will always stay below the name. I wanted it to appear above the name for testing, so that I know it is working correctly as it should. Which it doesn't.

    Oh and this by the way did not work at all:

    What am I doing wrong? Or am I ordering too soon?

  • I'm not quite sure what you're asking or what's wrong with your project, but z-ordering by instance variable in an ordered for loop works as expected.

    You cropped out the event numbers in your screenshot... is your z order sorting event a top level event? Newly created objects, outside the immediate event they are created in, can't be picked again until the next top level event. At least I think this is still the case.

  • Okay that was a good hint about the top level event. Both the text creation function call and the z ordering where inside the on selection changed event of the list object.

    Now I have a top level trigger_order_z check that will order z when it's 1 and set itself to 0 afterwards. Works perfectly now. Thanks.

    Edit: Got it even simpler. Now I made an On Text created -> order z event. So I do not need to trigger or use variables at all.

    Edit 2: On Text created won't work. Don't know why. Guess I have to trigger variables..

    Last Edit:

    Okay I did some testing. The only way I got it working correctly while still being automated without me needing to manually trigger the z ordering was as follows:

    When I used z ordering inside the On Text created event it just did not order any text at all. Even when wait was used. So I need to trigger a variable and in the following event I can order z. I guess it has to do with something like On Text created it can not access instance variables yet.

    When using the Sort event the first time the text is created will appear on the bottom of the layer for no reason. The second and following times the class is changed it works as inteded. Just the first time the class icon will not appear because z index will be below the character frame.

    Anyway. The way I sat it up in the screenshot works.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • On text created is a good idea, but only the text that was created is picked.

    Did you add a pick all text in that event?

  • Ohhhh. Stupid me! I will test it tomorrow with pick all. No I did not do that because I didn't think of that. Thank you for that hint. :D

    Edit:

    Tested it and still the only way it works as inteded is from my screenshot above. I guess that's because On Text created is triggered simultaneously and not after the text creation which will not make the local variables accessible.

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