Closed svdragster closed 5 years ago
This works fine for me in both 3.15 and master branch:
var block = this.matter.add.sprite(400, 300, 'block');
var data = block.toJSON();
console.log(data);
It seems to happen when the Scene that the sprite is added in has been stopped. I'm saving all game objects in the scene when switching to the main menu. Calling toJSON() before stopping the current scene seems to work fine. Is that intended behaviour?
That's because the Sprite no longer has a physics body, as the Scene has been stopped and the world cleared, so it can't read the x/y position from the body. This is too far outside the bounds of acceptable use to warrant changing I'm afraid.
So far no solution on my forum thread: https://phaser.discourse.group/t/matterjs-and-tojson/443
Calling toJson() on MatterJS Objects results in the exception: