Allwyn Menezes Posted September 25, 2016 Share Posted September 25, 2016 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 More sharing options...
samme Posted September 26, 2016 Share Posted September 26, 2016 May be better using `addOnce`: node.events.onInputDown.addOnce(TheGame.assignNode, TheGame); Link to comment Share on other sites More sharing options...
Recommended Posts