Sign in to follow this  
KungFuFlames

How to make Sprite/Image not Interactive ?

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 :)

Share this post


Link to post
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)`.

Share this post


Link to post
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);
            })

 

Share this post


Link to post
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.

Guest
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.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.