Jump to content

Phaser Arcade Collide


altioc
 Share

Recommended Posts

I've read some of the other posts about the collide method but none of the made sense to me. this is what code I have 

this.physics.startSystem(Phaser.Physics.ARCADE);sprite = this.add.sprite(5, 5, 'test');sprite.width = 50;sprite.height = 50;sprite2 = this.add.sprite(10, 10, 'test');sprite2.width = 50;sprite2.height = 50;this.physics.enable(sprite, Phaser.Physics.ARCADE);this.physics.enable(sprite2, Phaser.Physics.ARCADE);console.log(this.physics.arcade.collide(sprite, sprite2));

this prints out 'false'

 

and I was kinda hoping it would move the sprites so they weren't overlapping. I don't really know how Arcade Physics works... the overlap method returns 'true' if that helps.

 

Thanks

Link to comment
Share on other sites

If you are just trying to have the two different sprites you are using have collision detection you will need to put this in your update function

 

 

this.game.physics.arcae.collide(sprite, sprite2);

 

 

 

I am not entirely sure why you are using console.log maybe I am missing something in your question? Let me know if this helps or if you meant something else wiht your question.

Link to comment
Share on other sites

If you are just trying to have the two different sprites you are using have collision detection you will need to put this in your update function

 

 

this.game.physics.arcae.collide(sprite, sprite2);

 

 

 

I am not entirely sure why you are using console.log maybe I am missing something in your question? Let me know if this helps or if you meant something else wiht your question.

I tried moving it to update but nothing happens. I used console.log because a boolean is returned by the function, true if it worked and false if it didn't. I just want the overlapping squares to not be overlapping anymore lol.

Link to comment
Share on other sites

Wait so your sprites are overlapping and you just dont want them to? You just need to edit the placement of the sprites on your stage then, adding collision for them at their current placements is most likely going to do nothing. Especially since they are static and not moving.

Their placement is random and I was hoping there was some sort of physic function that could automatically move them.

Link to comment
Share on other sites

  • 2 weeks later...

Collisions won't work without the bodies having a velocity (body.velocity.x/y), because it's velocity that is used by Phaser to know how to 'repulse' the bodies. So collision on perfectly still objects will not happen.

 

I don't know if it will work if bodies are already overlapping when game starts though, but I see no reason why it wouldn't.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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