Jump to content

onInputDown.add() and onInputUp.remove() on same sprite is not working


Allwyn Menezes
 Share

Recommended Posts

I'm unable to remove event listener from a particular sprite in consideration. Please refer the following code and the comments for more details:

TheGame.prototype={
                //..more code here
                create: function() {
                    game.scale.pageAlignHorizontally = true;
                    game.scale.pageAlignVertically = true;
                    this.createLevel();
                },
                createLevel: function() {
                    var nodeCounter = 1;
                    for (var i = 1; i <= gameOptions.rows; i++) {
                        for (var j = 1; j <= gameOptions.cols; j++) {
                            this.addNode(i, j, nodeCounter);
                        }
                    }
                },
                addNode: function(x, y, c) {
                    var node = game.add.sprite(100 * x, 100 * y, "node");
                    node.belongsTo = null;
                    node.coordinate = new Phaser.Point(x, y);
                    node.pos = c;
                    nodes[c - 1] = node;
                    node.inputEnabled = true;
                    //On mouse down 'assignNode()' is called
                    node.events.onInputDown.add(TheGame.assignNode, node);
                    //But on mouse up 'assignNode()' is not removed from the listener
                    node.events.onInputUp.remove(TheGame.assignNode, node);
                }
}    

TheGame.assignNode = function(node) {     
  //does something
}       

Thanks & Regards

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.

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

  • Recently Browsing   0 members

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