1
\$\begingroup\$

I am currently using Kryo for serialization. I have a Player class, but it extends Sprite. Sprite isn't serializable. This means I can't serialize Player as a whole. Is there another way to do this? Or should I make a separate class for every object that needs to be saved, and manage all the data that needs to be saved in there?

This is my first game and I'm going for a top-down (like pokémon) RPG game. I also need to save locations of monsters and animals in certain maps etc. So I'm not sure if this would be the right way to go about it? I can't find that much about this topic for games and kryo in specific online, so hopefully someone can enlighten me a bit.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ What's leading you to want to serialize the whole player class, rather than just the player's persistent data (like a PlayerStats object)? Presumably a fair bit of the data stored in Player doesn't change from one run of the game to another (like the player's bounding box size), or has no long-term meaning (eg. the current frame of animation it's displaying), so it doesn't need to be saved. \$\endgroup\$
    – DMGregory
    Jul 31 '19 at 23:14
  • \$\begingroup\$ @DMGregory Yeah that's exactly what I mean. I don't really have a PlayerStats object, but that was actually my question. Should I create such objects for everything I need to save? All Player information is currently in the Player object itself. (Not really following a MVC pattern, I know. Probably wouldv'e been easier as I could just serialize the Player model) But I figured I could make every variable transient that I wouldn't need to save. But that's not even possible since Player extends Sprite. \$\endgroup\$
    – Tipsi
    Jul 31 '19 at 23:25
  • 1
    \$\begingroup\$ I do recommend distinguishing between "a live player character embedded in the web of our running game's systems" and "information about a player character that we want to save cold on-disc between game sessions" - they're logically very different concepts, and will likely get more different as your game evolves. \$\endgroup\$
    – DMGregory
    Jul 31 '19 at 23:29
  • \$\begingroup\$ Are you sharing instances of your sprite data (i.e. if you have 4 rocks, do you load the rock sprite 4 times, or do you have 4 copies of one rock texture)? And why does Player extend Sprite rather than hold an instance of it? \$\endgroup\$
    – Pikalek
    Aug 1 '19 at 13:59
  • \$\begingroup\$ @Tipsi The question is, when the user is loading their previous saved file, what information do you need to re-construct their player character? In pokemon (at least the early ones) you couldn't alter the appearance of your character, so no information is saved about it. If in a game (for example) the user can equip different clothes, you would need to save the information of which cloth it is (not the entire texture, just an ID, so you know which one it was). \$\endgroup\$
    – TomTsagk
    Aug 2 '19 at 8:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.