How do I create a 2.5D Tree Order Effect?

0 favourites
  • 10 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • I'm trying to create an effect where it looks like the Sprites are actually in a 3D World instead of a 2D.

    So if a Tree is higher (on Y) in a layout, it should be behind the one that is closer. You can see what I mean on the picture; it just looks wrong, some Trees are over others, when they shouldn't be.

    Code: The player has ImagePoint(1) at his feet and Trees have ImagePoint(0) at the bottom of a Tree's trunk. In my eyes this code is working and I've tried different methods using variables, but nothing really worked correctly, I'd gladly do even do it a different way, just so it finally works.

    Layer order: ObjectsUnderPlayer, Player, Objects

  • You can use the system sorter for that:

    dropbox.com/s/27p70ssxjm6q0kn/treeZ.c3p

  • That does work for the Trees, but when I try to do the same Sort via an instance variable for the Player (except every tick) it fails... Do you know why that happens?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can do this with only 2 actions, and without the cost of "For Each"

    create a new family "SortFamily." Put the player and the trees in it

    create an instance variable for the SortFamily called "SortFamilyY"

    create an empty condition and add the following actions:

    1. Set SortFamilyY to SortFamily.imagepointy(1)

    2. Sort SortFamily Z order by SortFamily.SortFamilyY

    This means every tick, the SortFamilyY variable will be set to the respective SortFamily's y position of the image point, and then the all the items in the SortFamily will be sorted

    Sidenote: When you do something like this, you might realize all the different items in the family have different numbers of image points, so calling on "Image Point 3" won't be feasible, since one item already has 7 image points and another only has 1. I would recommend naming your image points instead of using numbers. "Bottom" "Top" etc

  • Thank you newt and kidswithcrowns, being able to do it in two actions is quite amazing! This is made my day thanks again, works like a charm =]]

  • kidswithcrowns Do you know of any way without the family? Switched to Spriter, some objects are now Sprites because they have to be and some SCML, so I can't really make them be together in one family

  • System Sort Z-order action is very efficient (performance wise), but to use it with multiple sprites you need to combine them into a family.

    You can do the same without a family, but this may work a bit slower on large layouts:

    .

    Also, are you using Spriter to animate the player? Then you probably already have an invisible sprite like "PlayerBox" (which your Player Spriter object is pinned to). So you can put that PlayerBox sprite into the family together with trees, z-sort them and then use "Z Order Move Player to object PlayerBox" on every tick.

  • I only use a Sprite for the Spriter object on the Player, I'm not sure of the performance impact of using another sprite for each Spriter object I would have, since the pinning and just having double the amount of already lots of objects a survival game would have. What's your view on this? I'm not very experienced when it comes to these things. Which would be more efficient? The new Sort without the family or one with a family where each Spriter object would be pinned to another sprite?

  • So you currently only have one Spriter object, for the player, but planning to add many more for enemies, trees etc.? If all objects are going to be Spriter objects, you can add them to a family for z-sorting.

    I don't know which method will be faster. You can try the one that doesn't use families for now and modify it later if you notice that it uses too much cpu.

  • u can also do it the old way using Y instead of Z ... but it might be to heavy with to many objects in screen.

    Edited: u need all objects that are supposed to be sorted to be put in 1 big family... so they all get sorted, as dop suggested.

    message quoted from this dusty topic: set z-order with number

    Sort by Y coordinate:+ For each Sprite order by Sprite.Y ascending -> Sprite: send to front

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