javascript - socket.io 断开连接让玩家精灵落后
问题描述
在用户断开连接时,断开连接的玩家的精灵仍然留在其他用户屏幕上。我不确定为什么。
编辑:它是固定的。当玩家加入时,我有重复的套接字事件。
服务器端:
socket.on('disconnect', function () {
removePlayer(self, socket.id);
delete players[socket.id];
io.emit('disconnect', socket.id);
});
function removePlayer(self, playerId) {
self.players.getChildren().forEach((player) => {
if (playerId === player.playerId) {
player.destroy();
}
});
}
客户端:
this.socket.on('disconnect', function (playerId) {
self.players.getChildren().forEach(function (player) {
if (playerId === player.playerId) {
player.destroy();
}
});
});
解决方案
推荐阅读
- compiler-errors - 程序不包含适合入口点的静态“Main”方法 ///
- aws-lambda - 如何在无服务器中保护 AWS 访问密钥
- javascript - JavaScript 中的“$$("a")” 是什么意思?
- python - 等待队列填充python多处理的最佳方法
- dialogflow-es - Dialogflow 的后续意图
- angular - 如何使用Angular 6从带有参数的服务器获取URL
- css - CSS - 内部 div 不占用可用高度
- android - ionic:添加 android 和构建 apk 时出错
- java - onProgressUpdate 可以在活动中重载吗?
- r - `$<-.data.frame`(`*tmp*`,循环为 R 中的错误