Jump to content

Rectangle collides with Sprite.Body


Salvatore
 Share

Recommended Posts

Hi \o

 

I'm trying to collide a rectangle with a sprite.body, and nothing happends!

 

I allready try Phaser.Rectangle.intersects, Phaser.Physics.Arcade.intersets and Phaser.Physics.Arcade.overlap and nothing work!

 

I have to enable something?

 

Thanks!

Link to comment
Share on other sites

The rectangle has to be another body, so create a sprite with null as the source, enable physics and set the body's size:

var rect = game.add.sprite(0, 0, null);game.physics.enable(rect, Phaser.Physics.ARCADE);rect.body.setSize(50, 50, 0, 0); // set the size of the rectangle

Then you can use:

game.physics.arcade.overlap(rect, sprite, function(r, s) {  // overlap code here, with r and s corresponding to the rect and sprite objects that have overlapped});
Link to comment
Share on other sites

 

The rectangle has to be another body, so create a sprite with null as the source, enable physics and set the body's size:

var rect = game.add.sprite(0, 0, null);game.physics.enable(rect, Phaser.Physics.ARCADE);rect.body.setSize(50, 50, 0, 0); // set the size of the rectangle

Then you can use:

game.physics.arcade.overlap(rect, sprite, function(r, s) {  // overlap code here, with r and s corresponding to the rect and sprite objects that have overlapped});

 

It's Alive!!!

 

Thanks man \o

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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