Jump to content

Overlap between sprite and staticGroup and Not working


JesusJoseph
 Share

Recommended Posts

I am trying to check when a physics sprite and a staticGroup overlap. But the callback function is not called. there is not error 

Please note that if I change the staicGroup to group then its working. But the letters are falling down. 

But I need to move the letters from left to right and not falling. To move the static group objects from left to right I am updating the x value in the update function. Is this a correct way to do it?

Can someone please help me.

//Sprite Object
this.mainBird = this.physics.add.sprite(game.config.width / 3, 150, 'YellowBird1');

//Static group
this.letters = this.physics.add.staticGroup();
this.letterA = this.letters.create(400, 268, 'A');
this.letterB = this.letters.create(600, 400, 'B');
this.letterC = this.letters.create(650, 250, 'C');
this.letterD = this.letters.create(450, 220, 'D');


//Overlap code
this.physics.add.overlap(this.mainBird, this.letters, this.collectLetter, null, this);

//Callback Function
collectLetter() {
    console.log("collect")
}

 

When I debug into phaser.js i found that the result in the below code is returning as blank. This is in line number 82393 in phaser.js (3.7.1) version.

var results = (group.physicsType === CONST.DYNAMIC_BODY) ? this.tree.search(minMax) : this.staticTree.search(minMax);

The min and max X and Y values are not matching even though I am updating the x value of the group objects inside update function .

 

Edited by JesusJoseph
Found the line in phaser.js which return blank even though the objects overlapped.
Link to comment
Share on other sites

It sound like you should use a dynamic group instead.

this.letters = this.physics.add.group(/* ... */);

Phaser.Actions.Call(this.letters.getChildren(), function (letter) {
    letter.body.allowGravity = false;
});

 

Link to comment
Share on other sites

@Samme

Thanks for your reply. After I changed the group to dynamic and set the gravity correctly then it's working correctly

BUT the actual issue for me is I am moving the static/dynamic object by changing the x value inside the Update function.

If I move the dynamic group object by changing the x value inside the update function then the collider or overlap function is not working. 

Only when I move the group objects using below code then its overlap is working as expected.

this.letterA.setVelocityX(-160);

Not sure its a bug or this is what @rich plan to code, like for dynamic objects we should move them only using setVelocity and not changing the x or y value inside update function.

The sprite is working correctly even if we move it by changing the x/y value inside the update function.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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