Salvatore Posted May 16, 2014 Share Posted May 16, 2014 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 More sharing options...
lewster32 Posted May 16, 2014 Share Posted May 16, 2014 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 rectangleThen 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}); Salvatore 1 Link to comment Share on other sites More sharing options...
Salvatore Posted May 16, 2014 Author Share Posted May 16, 2014 The http://docs.phaser.io/Phaser.Physics.Arcade.html#enableBody seems not work with rectangles... Link to comment Share on other sites More sharing options...
Salvatore Posted May 16, 2014 Author Share Posted May 16, 2014 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 rectangleThen 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 More sharing options...
lewster32 Posted May 16, 2014 Share Posted May 16, 2014 You're very welcome Link to comment Share on other sites More sharing options...
Recommended Posts