Anshu Posted July 20, 2015 Share Posted July 20, 2015 HI Guys, Need a help. How can I make a button collidable object? I am using a group of buttons each having a different label. when a bullet hits any button i want to extract that label of that particular button. var bullets; bullets = game.add.group(); bullets.enableBody = true; bullets.physicsBodyType = Phaser.Physics.ARCADE; game.physics.enable(bullets, Phaser.Physics.ARCADE); var button = game.add.button(100, 400, 'button'); game.physics.enable(button, Phaser.Physics.ARCADE); game.physics.arcade.collide(bullets, button, collisionHandler, null, this); function collisionHandler (bullet, button) { button.kill();bullet.kill();} But my bullet is not colliding with the button. Please help!!!!! Link to comment Share on other sites More sharing options...
NewMember Posted July 20, 2015 Share Posted July 20, 2015 i think you need add sprites to bullets group . Link to comment Share on other sites More sharing options...
CodeToWin Posted July 20, 2015 Share Posted July 20, 2015 what is it doing exactly? Is the bullet passing right through? Link to comment Share on other sites More sharing options...
Anshu Posted July 21, 2015 Author Share Posted July 21, 2015 Yes the Bullet is passing right through the button. No collision is detected there or the collisionHandler function is not called. I want them to collide and call collisionHandler function. please help!! Thanx in advance. Link to comment Share on other sites More sharing options...
CodeToWin Posted July 21, 2015 Share Posted July 21, 2015 you need to use overlap! game.physics.arcade.overlap(bullets,button, collisionHandler, null, this); Link to comment Share on other sites More sharing options...
Anshu Posted July 21, 2015 Author Share Posted July 21, 2015 I changed the code game.physics.arcade.collide(bullets, button, collisionHandler, null, this); to game.physics.arcade.overlap(bullets, button, collisionHandler, null, this); rest code remain same.. The bullet is passing through. the function is not coming to collisionHandler Link to comment Share on other sites More sharing options...
Recommended Posts