Overlapping identical copies of the same object

0 favourites
  • 12 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • Hi!

    Tell me how to make an overall for identical copies of the same object?

    For example, there is a Sprite. There are 10 copies of it on the layer. Two of them crossed - how to get them?

  • If you mean pick the two that are overlapping there is something called 'Pick nth instance' under System, where 0 and 1 are the two instances overlapping.

  • Another popular method is to create a family with this sprite, and then you'll be able to use "Sprite overlapping Family" condition. Where you could refer to both instances separately.

  • And how to get all the participants of the overlap. for example, when one copy overlaps four other copies?

    Is it possible to get them in a loop?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Well I hate to post the same thing again but use Pick nth instance

  • Well I hate to post the same thing again but use Pick nth instance

    I'm sorry, my English is very bad, and the translator does not always translate well

    But I have another question. How can I call Pick with Action?

    For example, two copies of the same sprite collide and in the condition you need to select the first copy, and in the action take a variable from the second copy and assign it to the first copy

  • Another popular method is to create a family with this sprite, and then you'll be able to use "Sprite overlapping Family" condition. Where you could refer to both instances separately.

    Thanks

    How can I call Pick using Action?

    For example, two copies of the same sprite collide and in the condition you need to select the first copy, and in the action take a variable from the second copy and assign it to the first copy

  • Add the sprite to a family. Define the variable on the family and remove it from the sprite. Then you can use this code:

    Sprite is overlapping Family
    .. Family set var to Sprite.var
    

    Depending on your task you might need to pick the correct sprite instance first. For example if you are using Drag And Drop behavior, then the code will be:

    Sprite On Drop
    Sprite is overlapping Family
    .. Family set var to Sprite.var
    
  • Add the sprite to a family. Define the variable on the family and remove it from the sprite. Then you can use this code:

    > Sprite is overlapping Family
    .. Family set var to Sprite.var
    

    Depending on your task you might need to pick the correct sprite instance first. For example if you are using Drag And Drop behavior, then the code will be:

    > Sprite On Drop
    Sprite is overlapping Family
    .. Family set var to Sprite.var
    

    Голливудские холмы

  • > Add the sprite to a family. Define the variable on the family and remove it from the sprite. Then you can use this code:

    >

    >

    > > Sprite is overlapping Family
    > .. Family set var to Sprite.var
    > 

    >

    > Depending on your task you might need to pick the correct sprite instance first. For example if you are using Drag And Drop behavior, then the code will be:

    >

    >

    > > Sprite On Drop
    > Sprite is overlapping Family
    > .. Family set var to Sprite.var
    > 

    Thank you very much!

    And how can the values of two copies of the same object be exchanged during an overlay?

    It was:

    Copy 1 value 22

    Copy 2 value 55

    After the overlay:

    Copy 1 value 55

    Copy 2 value 22

    This is much more difficult

  • Use a local variable to temporarily store the value of one instance.

    Sprite is overlapping Family
    .. Local Variable temp=0
    
    .. Set temp to Sprite.var
    .. Sprite set var to Family.var
    .. Family set var to temp
    
    

    Only in this case you should probably use "On Collision" event. Because Overlapping can happen many times per second, so the instances will continue swapping values again and again many times.

  • Family aproach is the solution. Create family first, add Sprite to it. Previous instance variable won't inherited to family class so create family instance variable with different name.

    Filter the IID first by picking lowest ID to identified as first copy by using loop 'For each (ordered)' & set expression to Sprite.IID then add 'stop loop' in action.

    This will pick first copy or earliest created Sprite instance.

    An example with extra group tag:

    dropbox.com/s/jaa75kb7odqjs9f/overlap_group_tag.capx

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