该方法用于将 MovingEntity 实例转换为 JSON 格式。
movingEntity.toJSON();
该方法返回一个包含 MovingEntity 实例所有属性的 JSON 对象。
const entity = new MovingEntity({
id: 1,
x: 0,
y: 0,
speed: 10,
direction: 0
});
const json = entity.toJSON();
console.log(json);
// 输出结果:
// {
// "id": 1,
// "x": 0,
// "y": 0,
// "speed": 10,
// "direction": 0
// }