User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11

Thread: Best approach for Y Sorting

  1. #1
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export ModuleUnicode Add-on
    mobichan's Avatar
    Join Date
    Oct 2007
    Location
    Buffalo, NY
    Posts
    3,297
    Mentioned
    27 Post(s)
    Tagged
    0 Thread(s)

    Best approach for Y Sorting

    I am starting to work on a game with a 3/4 overhead viewpoint (think Final Fight or Streets of Rage) and I plan to use a lot of active objects for scenery and interactive stuff. I have always had issues in the past with sorting objects properly, especially when the player and moving enemies/objects are constantly changing their Y (depth) positions. Can anyone offer a low overhead solution for managing the sort order of things in a scene?

    I have tried using the Layer Object's "Sort Descending Y" in the past, but found out it is a very costly operation to always perform, especially on mobile. Is this something that ForEach loops would be better at handling? I had considered a system where objects are laid out in the scene with preset depth values stored in a var. Then leave large gaps in the depth value ranges to allow for a lot of moving objects to exist inside without mucking up the static scenery's depth arrangement.

    I searched around but can't find any good examples or suggestions on best practices. Anyone have any ideas?

  2. #2
    Clicker

    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    May 2015
    Posts
    135
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)
    Ugh, I typed out a long response and it disappeared. So if it shows back up, excuse me for the double post....

    I've done multiple top down engines with lots of Sort By calls and not had any hit on performance (but not on mobile). I'd recommend trying Sort By Alt Val though instead of Y position as it gives you a lot more ability to fine tune how things sort. Choose an Alt value you can use on all of your objects (AA or something far enough down it won't mess up different object types) that will be sorted and add them to a universal group (ex: generic 1). Then on creation or at the start of the frame set their AA value to something like (this may be a bit rough I'm just typing from memory quickly):

    YBottom(Active) * Z + (X(Active)/1000.0) where "Z" can be a unique integer used by different object groups to help define specific sorting (Example: background decorations (Z of 5) can be sorted with each other but will always be behind Foreground characters( Z of 10)). I add a small decimal based on X position so that overlapping objects with the same Y position and Z multiplier don't flicker between each other. Moving objects can have these values always updated with ForEach loops if there are multiples). You might be able to adapt this to your own custom ForEach system and not use the Layer object, but no idea how that would improve performance.

    Also, what happened to Slayin' 2? I was following the blog posts and then they stopped. Have you moved on or is this some iteration of it? I do recall it was going to have multiple lanes to fight in.

  3. #3
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export ModuleUnicode Add-on
    mobichan's Avatar
    Join Date
    Oct 2007
    Location
    Buffalo, NY
    Posts
    3,297
    Mentioned
    27 Post(s)
    Tagged
    0 Thread(s)
    @CuddlyGoose Thanks for the suggestion. I will give it a try and see where it goes. I guess the division by 1000 is defining your max objects per "Z" to 1000? I was always unsure if the sorting in Fusion allowed floats, but hopefully it does.

    This is actually for a possible next project after Slayin2. I want to resurrect an old idea I did a while ago when I was just using a Layer Object Decreasing Y sort. I did a game on iOS (Treasure Buster, I think) that originally had an Always -> Sort Decreasing Y and it ended up being a serious bottleneck on mobile, so I had to make a lot of obnoxious sorting rule code instead. Since then, I am always wary of using the Sort by Decreasing Y, but maybe I am too overly cautious.

    As for Slayin2, it is being ported to Switch now with a publisher. We are finishing up bug testing so it shouldn't be long before it hits the eshop. You can follow my twitter ( https://twitter.com/pixellicker ) or FDG Entertainment ( https://twitter.com/FDG_Games ) on twitter to get current news. Also, Slayin2 does use unique layers for the 2 planes, so there is very little manual sorting.

  4. #4
    Clicker

    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    May 2015
    Posts
    135
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)
    The X position being divided by 1000 is a random example, but the idea is to just add a small decimal on after the Y position is multiplied with the Z value you have for each type of object. So if you have 2 objects on the same Y position and they are the same qualifier group they don't flicker back and forth between which one is in front. I never thought about the Sort by Alterable value being different than using alterable values for anything else, so I actually don't know, but it stopped my flickering problem when I started tacking on a tiny extra value. If the X value is too big, you can get objects overlapping in weird ways.

    Also just followed you (I'm Gold5Games). I thought I already had followed to be honest.

  5. #5
    Clicker Fusion 2.5 MacFusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleiOS Export ModuleInstall Creator Pro
    Fusion 2.5 (Steam)
    elvisish's Avatar
    Join Date
    Oct 2014
    Posts
    753
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)

  6. #6
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export ModuleUnicode Add-on
    mobichan's Avatar
    Join Date
    Oct 2007
    Location
    Buffalo, NY
    Posts
    3,297
    Mentioned
    27 Post(s)
    Tagged
    0 Thread(s)
    Hahaha. That is painfully simple and probably has the same issues CuddlyGoose's division by 1000 fixes. But thanks for the link. It is always good to have different ideas on how to approach the problem.

  7. #7
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export ModuleUnicode Add-on
    mobichan's Avatar
    Join Date
    Oct 2007
    Location
    Buffalo, NY
    Posts
    3,297
    Mentioned
    27 Post(s)
    Tagged
    0 Thread(s)
    @CuddlyGoose : ok, I tried your method and it doesn't seem to work. I am guessing I messed up somewhere int he eventing, but I am creating a grid of objects at runtime with a fastloop and then running the layer obj Sort Decreasing by Alt Var when I press a key. You can see the issue in the image. The sorting is not maintained in the rows, even though the vars are being set with the proper decimals (smaller decimal values to larger values going left to right).

    Any idea what is wrong here?

    sorting_issue.gif
    sorting_issue_events.gif

  8. #8
    Clicker

    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    May 2015
    Posts
    135
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)
    @mobichan I recreated your example because I can't find any of mine at the moment (probably on a backup in storage) but it appears the X decimal isn't working, but not dividing the X works fine (I must have remembered wrong) in this instance. You can also use a spread value on creation or any other unique modifier to maintain the order they are created in.

    But yeah, just add the X value as an integer as is and it works fine in my test.

  9. #9
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export ModuleUnicode Add-on
    mobichan's Avatar
    Join Date
    Oct 2007
    Location
    Buffalo, NY
    Posts
    3,297
    Mentioned
    27 Post(s)
    Tagged
    0 Thread(s)
    Sadly, if I go back to integers, then there is an issue where moving horizontally doesn't maintain the proper sort order with the moving player object (the light blue square in my image). Using floats actually did that part correctly, but didn't maintain the order among the purple squares themselves.

    Hers is my mfa if you want to take a look.
    beatemup_engine2.mfa

  10. #10
    Clicker

    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    May 2015
    Posts
    135
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mobichan View Post
    Sadly, if I go back to integers, then there is an issue where moving horizontally doesn't maintain the proper sort order with the moving player object (the light blue square in my image). Using floats actually did that part correctly, but didn't maintain the order among the purple squares themselves.

    Hers is my mfa if you want to take a look.
    beatemup_engine2.mfa
    Took a quick look. Sorry I'm a bit fuzzy on the details from when I did this, but you can simply increase your sort order values (I made them 50 as a quick test) so the X integer doesn't need to be a tiny float (you can still divide by 10 if you'd like to keep the numbers smaller with less issue for value overlap).

    beatemup_engine2_edited.mfa

Page 1 of 2 1 2 LastLast

Similar Threads

  1. For backgrounds, what approach do you recommend?
    By Luma Games in forum Fusion 2.5
    Replies: 2
    Last Post: 29th July 2017, 12:14 AM
  2. Best approach to loading 50 images?
    By Just4Fun in forum Fusion 2.5
    Replies: 2
    Last Post: 26th June 2015, 03:43 AM
  3. Best Approach for Universal Binary?
    By BHGames in forum iOS Export Module Version 2.0
    Replies: 5
    Last Post: 15th March 2011, 08:41 PM
  4. Z Sorting or Depth Sorting, how to do it?
    By BREK in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 28th October 2008, 12:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •