Firebase与数据更新滞后 - 多人游戏

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Firebase与数据更新滞后 - 多人游戏相关的知识,希望对你有一定的参考价值。

我使用Firebase作为多人开放世界游戏的后端数据库。我需要写入速度高达100毫秒,以保持所有播放器的实时更新。我的游戏图形在LibGdx引擎中保持平稳,但随后Firebase滞后于写入数据,显示对手玩家的延迟位置。我使用界面与核心LibGdx游戏类通信到android功能(因为LibGdx中没有Firebase)。

请建议我实现更新数据的平滑机制,并使用Firebase实现流畅的多人游戏方法。 (包括LibGdx)

以下代码显示了我的Firebase代码段:

//For writing owners location update
taskMap.clear();
taskMap.put("x", Connect.carX);
taskMap.put("y", carY);
taskMap.put("angle", angle);
taskMap.put("rx", rx);
taskMap.put("ry", ry);
taskMap.put("fx", fx);
taskMap.put("fy", fy);
taskMap.put("wheelAngle", wheelAngle);
db.child("public").child(firebaseAuth.getUid()).updateChildren(taskMap);
taskMap.clear();
taskMap.put("damage", damage);
taskMap.put("gear", gear);
taskMap.put("fuel", fuel);
db.child(firebaseAuth.getUid()).updateChildren(taskMap);


//For reading opponent locations update
LibGdx.core.class.dummyCarUpdate(postSnapshot.getKey(),
Float.parseFloat(postSnapshot.child("x").getValue().toString()),
Float.parseFloat(postSnapshot.child("y").getValue().toString()),
Float.parseFloat(postSnapshot.child("angle").getValue().toString()),
Float.parseFloat(postSnapshot.child("rx").getValue().toString()),
Float.parseFloat(postSnapshot.child("ry").getValue().toString()),
Float.parseFloat(postSnapshot.child("fx").getValue().toString()),
Float.parseFloat(postSnapshot.child("fy").getValue().toString()),
Float.parseFloat(postSnapshot.child("wheelAngle").getValue().toString()));
答案

您正在寻找的技术称为插值。此技术允许您在连接到数据库的客户端上平滑结果移动。 Learn a bit about interpolation here

您需要存储以前的数据以使用新数据进行插值。您还将决定插值在状态之间的速度。

以上是关于Firebase与数据更新滞后 - 多人游戏的主要内容,如果未能解决你的问题,请参考以下文章

Firebase 实时多人游戏

Google Play 游戏服务中的多人游戏 API 将不再可用。如何迁移到 Firebase?

《Python多人游戏项目实战》第二节 使用pickle模块序列化数据

《Python多人游戏项目实战》第二节 使用pickle模块序列化数据

网络多人游戏架构与编程

《Python多人游戏项目实战》第一节 简单的方块移动