Jump to content

Graphics to a sprite and click on it, Not working

Arijit Naskar

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.inputEnabled = true;
      game.physics.enable(shapeSprite, Phaser.Physics.ARCADE);
// shapeSprite.body.velocity.x = 100;
      shapeSprite.events.onInputDown.add(onDown, this); 


    function onDown(sprite, pointer) {


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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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