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

 Share

  • Recently Browsing   0 members

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