Jump to content

Sprite input onInputDown


Krulvis
 Share

Recommended Posts

Hey guys,

 

I'm new here but struggling with an issue. Basically I want to enable a click function on a sprite. The sprite consists of one image which is duplicated throughout the width/height of the sprite:

The image itself is 32x32 meaning that for every width , height images have to be added.

this.tileSprite = this.game.add.tileSprite(      x, y, width * 32, height * 32, "solid_block", null, this.blocks    );    this.tileSprite.name = name;    this.tileSprite.body.immovable = true;    this.tileSprite.solid = true;    this.tileSprite.inputEnabled = true;    this.tileSprite.input.useHandCursor = true;    this.tileSprite.events.onInputDown.add(function(){            console.log("Selected: " + this.name);            this.select();    }, this);

The width and heigh may vary which in my case: width = 3, height = 3 creates a larger sprite consisting out of multiple of the same images:

Screenshot17-42-57.png?dl=1

 

The click function only works when I click on the first image of the sprite (you can see it holds 9 images, 3x3).

 

How do I code it so that wherever on the sprite you click, the onInputDown function is called ?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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