当第一个套接字连接时,两个图像被加载而不是一个 – Node.js

我正在尝试为我的游戏实现多人游戏function。 我正在使用node.js 当一个人连接时,图像应该被加载到浏览器。 相反,它加载两个图像。

inheritance人是我class的一部分

 var count = 0; //Keep track of which player we're oparating on function Car(id){ var that = this; //Reference to 'this' this.loadHero = function(){ that.id = document.getElementById(id); //Store the id of our charakter $(that.id).css({"display" : "block"}); } } 

客户端的node.js:

 var socket = io.connect('http://localhost:3000'); socket.on('entrance', function(data){ console.log(data.message); var num = (count > 0) ? count : ''; console.log("hero" + num); var hero = new Car("hero" + num); hero.init(); count++; }); 

当我启动我的服务器并连接。 我的控制台显示了以下内容

在这里输入图像描述

hero是我的第一个图像(首先连接的玩家)的ID。 hero1是第二个玩家,依此类推。 所以我不明白为什么当一个玩家连接时我的图片都被加载了。

任何帮助是极大的赞赏!