Jump to content

Is there an event when something stops overlapping?


Recommended Posts

Hello everyone!

I hope you are having an excellent day to help me out 😃

Long story short, I'm trying to toggle a boolean when something overlaps and most important, when it stops overlapping.

I created the example below to get which is the parameter that changes when an overlap occurs:

this.w1 = this.physics.add.sprite( 100, 100, 'atlas-minions', `blue/walk/minion_00.png` ).setInteractive( { draggable: true } );

this.w2 = this.physics.add.sprite( 400, 100, 'atlas-minions', `red/walk/minion_00.png` ).setInteractive( { draggable: true } );
this.w3 = this.physics.add.sprite( 800, 100, 'atlas-minions', `red/walk/minion_00.png` ).setInteractive( { draggable: true } );

this.groupa = this.add.group();
this.groupa.add( this.w2 );
this.groupa.add( this.w3 );
console.log( 'w1 BEFORE', this.w1.body.touching )

this.physics.add.overlap( this.w1, this.groupa, () => {
    console.log( this.w1.body.touching )
}, null, this );

But when I drag w1 over w2 or w3, the console.log prints the same result as when w1 is created:

down: false
left: false
none: true
right: false
up: false

How come this.w1.body.touching.none = true even when is actually touching something?? ლ(ಠ_ಠლ) 

Is some other parameter that registers the overlapping?


Also I saw another solution here, but it only works with single objects. In my game I needed this to work with groups instead. I know I could convert the code but it looks like a workaround too big for something this simple. 


After many hours looking everywhere for an answer, I just ended up burnt.

Please send help ಥ_ಥ

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...