User Tag List

Results 1 to 10 of 10

Thread: Checking for collisions on multiple layers

  1. #1
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCHTML5 Export ModuleiOS Export ModuleSWF Export ModuleInstall Creator Pro
    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)
    chrilley's Avatar
    Join Date
    Jul 2006
    Posts
    1,013
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)

    Checking for collisions on multiple layers

    Does anyone know a clever way to check for collisions on multiple layers? For example I have my sprites on Layer 2 but my collision mask is on Layer 1 which is also invisible. This is mainly for projectiles so I want to avoid having multiple objects for collisions. The way I figured how to do it is that each object on Layer 2 has these four events:

    - Always
    Run a for each loop "collision"

    - On loop "collision"
    Move to Layer 1

    - On loop "collision"
    - Object is overlapping obstacle
    Destroy

    - On loop "collision"
    Move to Layer 2

    I have no idea how costly this would be performance-wise. What do you guys think?

    BTW - This is not intended to be a pixel-perfect detection system, it's mostly used for projectiles when they smash against walls and the player, etc.

  2. #2
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,159
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    Would have done the same

    Don't know how taxing "move to layer" is,
    but other solutions I can think of would require a couple extra actions x loop so a rough guess is that they would be anyway worse.

    Maybe a very little optimization could be:

    - Always
    Move to Layer 1
    Run a for each loop "collision"
    Move to Layer 2

    - On loop "collision"
    - Object is overlapping obstacle
    Destroy

    Don't know if/how faster that would be, maybe a little bit,
    but is shorter code-wise

    (not tested, but should work I guess?)

    Dumb question would be:
    why needing the collision mask to be on a different layer?
    But there's surely a good reason behind

  3. #3
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCHTML5 Export ModuleiOS Export ModuleSWF Export ModuleInstall Creator Pro
    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)
    chrilley's Avatar
    Join Date
    Jul 2006
    Posts
    1,013
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Ah yeah good idea, that's less events to go through at least. Maybe I can run an isolated stress test and see if there is a big difference.

  4. #4
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCHTML5 Export ModuleiOS Export ModuleSWF Export ModuleInstall Creator Pro
    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)
    chrilley's Avatar
    Join Date
    Jul 2006
    Posts
    1,013
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Actually it wouldn't trigger the On each of loop event anymore with that order, schrodinger. Did I do it wrong?
    Attached files Attached files

  5. #5
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,159
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    Yeah, I recall finding this didn't work, at times, not really sure why
    (I think after a foreach, scoping gets confused)
    (...this is why I put that "disclaimer" )

    so this is the inelegant workaround I usually do:

    chrilley_fumbles_1.mfa

    But not really tested on performances.
    At first glance seems to be very similar...
    guess the nicest code for you would win

  6. #6
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,159
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    I was curious and tested both solutions with the good old speed tester
    there's a slightly better performance from the "optimized" solution,
    but I wouldn't say the gain is very important, in a general use-case.



    (change outloop: layer is changed outside the foreach loop,
    while the other inside)


    And the gap grows with growing number of objects tested:




    But seems like it's a pretty taxing operation to do anyway.
    Starting to think checking collision mask through coordinates with bounding boxes (since you don't need precision) could be lighter?
    Could try another little test out of curiosity..

  7. #7
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,159
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    And this is a slightly quicker method in fact (seems like move to layer is more intensive).

    Just placed a collision detector on the other layer,
    on loop you place the detector at sprite X,Y
    and test for backdrop collisions.

    test_cmask.png

    It's more than twice as fast.

    But I guess you would have to store multiple animations for your different object types,
    and if you launch the loop on different objects at the same time
    don't know if you would have to switch the animation just once before the loop gets fired
    or do it multiple times inside the same loop (different objects, same qualifier..)

    Or you could go with a simple additional X and Y scaling of the detector
    (say you want to have a scalable bounding box based on Owidth/Oheight of the object to test)
    would still be faster than previous solution:



    (just a side note:
    bouncing works bad when detached from it's own object "on collision" event
    but I guess you won't really need to bounce in real-case,
    if you need to destroy it would be good imo)

    Sorry for flooding the thread, was interested in this as well

  8. #8
    No Products Registered

    Join Date
    Mar 2016
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    create a hitbox for each of the layers you want to test collision - have them share x/y positions?

  9. #9
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCHTML5 Export ModuleiOS Export ModuleSWF Export ModuleInstall Creator Pro
    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)
    chrilley's Avatar
    Join Date
    Jul 2006
    Posts
    1,013
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Thanks for doing help shrodinger! I might use a mixture of the methods actually. For some objects I want their animation and shape to be the collision mask while for some objects a square would do just fine so I think both approaches would work.

  10. #10
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCiOS Export ModuleInstall Creator Pro
    Julian82's Avatar
    Join Date
    May 2012
    Location
    outbuddies.com
    Posts
    990
    Mentioned
    50 Post(s)
    Tagged
    0 Thread(s)
    Hi guys,

    I normally go for the following approach:
    1. Beginn of frame loop (layering for collisions): Move ALL my actives that need collision detections to my collision layer
    2. Run the frame loop and check for collisions
    3. At the end of the frame loop (layering for renderer): Move my objects to the layers I want them to be displayed

    This way you detach the whole collision detection from the rendering, might not work for you in some cases though but I found it to be more simple and effective than most of the stuff I did before

Similar Threads

  1. pasting to multiple layers
    By lost_child in forum Multimedia Fusion 2 - Technical Support
    Replies: 10
    Last Post: 31st March 2010, 02:38 AM
  2. Collisions between 2 objects on different layers
    By Del_Duio in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 3rd December 2008, 04:06 AM
  3. ClickTeam Don't call collisions over layers OR
    By 00J in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 13th January 2008, 05:55 AM
  4. Multiple backround layers not working :(
    By Zenoff64 in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 27th November 2007, 09:40 PM
  5. Object Focus: multiple overlapping collisions
    By Fresh_Bagels in forum The Games Factory 2 - Technical Support
    Replies: 4
    Last Post: 14th March 2007, 05:18 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
  •