Jump to content

Can i make a button collide with a sprite?


Anshu
 Share

Recommended Posts

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

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

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

 Share

  • Recently Browsing   0 members

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