Jump to content

How to make Sprite/Image not Interactive ?


KungFuFlames
 Share

Recommended Posts

The following code fragment below is a funtion which is setting up all Sprites in Array to be interactive:

cellInputEnable(): void {
   this.boardUI.cells.forEach((entryCellUI) => {
       entryCellUI.setInteractive();
       })
}

It works perfectly later on in the eventListener. The problem is that I don't want to make all of the interactive. Let's just say that I want to make certain Sprites Interactive. So this going look like that: 

cellInputEnable(): void {
   this.boardUI.cells.forEach((entryCellUI) => {
   if (this.board.movementGenerator.piecesMap.get(selectedPiece).indexOf(entryCellUI.cell) > -1) {
                   entryCellUI.setInteractive();    
            }
       })
}

 That's cool. Now specific ones are interactive. After some methods I generate new desired Sprites to be interactive. How about the old ones? I tested it and they are still interactive which totaly mess up the logic. Is there a way to more them "non-Interactive"

 

Thank! 

Also if you have any suggestions how to make it more cleaner I would be happy to hear them :)

Link to comment
Share on other sites

You can `sprite.input.enable = false`. If you want to toggle interactive mode than it's perfect. And I think that's what you're trying to do. If you want to remove the input object from sprite you can do this: `this.input.disable(sprite)`.

Link to comment
Share on other sites

Thanks again!

I came up with diffrent solution. All the cell are interactive all the time. The main point is that they hava a specific event attach to them. So wherever they are clicked I'm checking if the clicked Object has a listener with the name. Something like:

 

this.game.input.on('gameobjectdown', function (pointer, gameObject) {
  if (gameObject.listenerCount('pieceInputDown') > 0) {
                gameObject.emit('pieceInputDown');
  }
}, this);

and the InputEnabling look this:

 private pieceInputEnable(): void {
            this.boardUI.pieces.forEach((entryPieceUI) => {
                entryPieceUI.setInteractive();
                entryPieceUI.addListener('pieceInputDown', this.pieceInputListener, this);
            })

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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