Question Regarding Sprite Overlap with Itself

0 favourites
  • 8 posts
From the Asset Store
A set of 10 pixel art animated magic effects with icons. 2 Fire, 2 Earth, 2 Wind, 2 Water, Portal, Explosion.
  • I have a sprite named SpriteX. When it overlaps with the same instance of SpriteX, I want to perform a certain action. In this case, I want to set its position to the first instance of the sprite where it overlapped.

    To achieve this, I have assigned a boolean variable to SpriteX, called Draggable_Boolean. Based on this variable, I have selected the desired sprite where I want to perform the action by adding an instance variable called "A" to it. Additionally, I've created a family called SpriteX_Family and assigned an instance variable called "B" to it.

    In the comparison logic, when A equals B and the sprites overlap, I intend to set the position of SpriteX to the SpriteX_Family. However, this approach is not giving the expected results. This is where I need assistance.

    Please take a look at the attached .c3p file for further details.

    easyupload.io/2f39z4

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Have a look to your modified file: drive.google.com/file/d/1rpj5V16O0qtfeZ7AxeuTn5A9CSVXJuN2/view

  • Thanks alextro, it works but has an issue

    Please check this video.

    easyupload.io/aouukz

    and I'm a little bit confused about the

    -> SpriteX: Set B to LoopIndex%3+10
    -> Text: Set text to LoopIndex%3+10
    

    The picking number here can be any number series, For example, I gave 10,11 & 12 for the example c3 but it can be any no series.

  • symbol "%" means modulo operation . So if you have 6 instances which start with iid 0 as first instance and iid 5 as last instance. In your case the iid is equal to loopindex due to loop condition "For each". Took an example from the iid or loopindex as an input to do modulo operation: 3%3 will return 0 as remainder and 5%3 will return 2 as remainder. So basically since I know they are equal pair for the object instances and want to assign them to the same instance variable value as input, I put modulo operation to quickly assign the value. Aside from that I recommend to use pin behavior to keep track of text position instead of using Every tick.

  • Thanks for your response,

    So if you have 6 instances that start with iid 0 as first instance and iid 5 as last instance. In your case the iid is equal to loopindex due to loop condition "For each". Took an example from the iid or loopindex as an input to do modulo operation: 3%3 will return 0 as remainder and 5%3 will return 2 as remainder. So basically since I know they are equal pair for the object instances and want to assign them to the same instance variable value as input, I put modulo operation to quickly assign the value.

    Yes, I understand that, but I am a bit confused about how to make the code work for any number. SpriteX and SpriteX_Family can represent any number, and the current LoopIndex%3+10 logic only applies when SpriteX.a has values 10, 11, and 12. If the series is different, we need to adjust the LoopIndex%3+10 accordingly.

    For that, I used a Boolean variable. Based on the Boolean's value, the logic is structured as follows:

    // Naming The Text w.r.t. the Sprite Instance Variable based on its Boolean
    + System: Pick SpriteX by evaluating SpriteX.Draggable_Boolean=0
    -> Text: Set text to SpriteX_Family.A_Family_IV
    
    + System: Pick SpriteX by evaluating SpriteX.Draggable_Boolean=1
    -> Text: Set text to SpriteX.A_IV
    
    

    However, I am uncertain about the comparison logic that should be used in this context. :/

    // The Main Picking logic, where I have issue
    + SpriteX: Is overlapping SpriteX_Family
    + SpriteX: A_IV = SpriteX_Family.A_Family_IV
    + System: Pick SpriteX_Family where SpriteX_Family.A_Family_IV = SpriteX.A_IV
    -> SpriteX: Set position to (SpriteX_Family.X, SpriteX_Family.Y)
    
    

    (IV = Instance variable)

    Here is the revised c3p file with improved naming to avoid confusion.

    easyupload.io/06k95o

  • Please help

  • Here I simplify everything by using container, pin behavior & removing unnecessary instance variable:

    drive.google.com/file/d/1nIxvtBbRGfGdkTuKb_O4QXdHCWI3EjuT/view

  • It works. Thank you alextro for your time. Appreciated. :)

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