【发布时间】: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()));
【问题讨论】: