Jump to content

Graphics to a sprite and click on it, Not working


Arijit Naskar
 Share

Recommended Posts

 

I am tryning to implement a click event on a graphics object. I have added the graphics object as a child of a empty sprite. and then applied an onInputDown event.

Below code of mine not working. 

The onclick event is not triggering. Please help.

 

    function create() {
      game.stage.backgroundColor = '#124184';
      shapeGr = game.add.graphics();
      shapeGr.lineStyle(5, 0xddff00, 1);
      shapeGr.moveTo(250, 100);
      shapeGr.lineTo(250, 0);
      
     
      shapeGr.boundsPadding = 0;
      
      
      var  shapeSprite = game.add.sprite(0, 0);
      
     
      shapeSprite.addChild(shapeGr);
      shapeSprite.inputEnabled = true;
     
      game.physics.enable(shapeSprite, Phaser.Physics.ARCADE);
      
    
// shapeSprite.body.velocity.x = 100;
      
      shapeSprite.events.onInputDown.add(onDown, this); 

    }

    function onDown(sprite, pointer) {
      console.log("clicked");
     }

 

Edited by rich
Removed 'phaser 3' from the title as it's v2
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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