【问题标题】:Firebase lagging with data updation - Multiplayer gameFirebase 数据更新滞后 - 多人游戏
【发布时间】:2019-04-09 17:17:14
【问题描述】:

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

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

以下代码显示了我的 Firebase sn-p:

//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()));

【问题讨论】:

    标签: android firebase libgdx


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢,我用同样的方法解决了我的问题。现在以 300 毫秒的间隔将数据更新到 Firebase,并使用插值进行平滑处理。相信我一切都很顺利。
    猜你喜欢
    • 2017-09-19
    • 2021-05-17
    • 2020-01-29
    • 1970-01-01
    • 2021-03-13
    • 2013-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多