Jump to content

Phaser Input duplication bug?


Costa1337
 Share

Recommended Posts

Every time I press enter after entering my nickname it creates a new player ingame. It should just allow it one time and then close the stage.
Anyone that can help me? Full source is here:

Retoosh.GuestNick = function (game) {
	this.game = game;
};

Retoosh.GuestNick.prototype = {
		create : function(){
			var bg_group = this.game.add.group();
			

			SOCKET.on("room found", Retoosh.Main.prototype.onRoomFound);
	        //here wee put the background image. I chose to let it fill the background ?!?
	        this.background = this.game.add.sprite(0, 0, 'back_guest');
	        this.background.width = Retoosh.WIDTH;
	        this.background.height = Retoosh.HEIGHT;
	        this.background.x = 0;
	        this.background.y = 0;
	        this.background.inputEnabled = false;
	        this.background.events.onInputDown.add(this.eventListener, this);
	        bg_group.add(this.background);
	        bg_group.scale.x = bg_group.scale.y;

	        //Now wee append the login form
	        var n = game.add.inputField(15, 300, { font: "36px", width: 369, padding: 9
	        });
			
	        var self = this;
	        //wee are now append a key listener to catch enter ;)
	        this.game.input.keyboard.addCallbacks(this.background, null, function(data) {
	        	if(data.keyCode != 13){
				return;
	        	}
	        	if(!n.value.trim()){
	        		//no value
	        		self.error("Please enter your nickname.");
	        		return;
	        	}

						USERNAME = CONFIG.guest_prefix + n.value.trim();
						SOCKET.emit("room request", {name: USERNAME});
	        }, null);
		},

		error : function(message){
			var result_lbl = this.game.add.text(0, 0, "", { font: "32px", fill: "#fa3e3e" });
		    result_lbl.x = 410;
		    result_lbl.y = 310;
		    result_lbl.text = message;
		},

		eventListener : function(s){

		}
};

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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