Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  How do you write SaveGame feature?  (Read 2307 times)
0 Members and 1 Guest are viewing this topic.
Offline Sonic96PL

Senior Newbie

« Posted 2012-08-18 18:00:04 »

Hi guys,
I was wondering how do you write SaveGame feature?
Long time ago, when my game used only String's and int's I used to use Serializable interface.

But now I stuck with this stupid problem, because of BufferedImage...
I know that there must be better solution than serializing objects.

Offline Gjallar

JGO Knight

Medals: 44
Projects: 1

Follower of Nurgle

« Reply #1 - Posted 2012-08-18 18:06:19 »

I believe you can serialize ImageIcons, so if you'd change your BufferdImage to be an ImageIcon you could serialize it.

I guess that's not really the solution you are looking for though  Tongue
Offline Sonic96PL

Senior Newbie

« Reply #2 - Posted 2012-08-18 18:09:26 »

No, saving textures is impractical...
I thought that XML can be nice, but I don't know.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline zngga
« Reply #3 - Posted 2012-08-18 18:22:58 »

It really depends on the type of game you are making. Obviously save data for an RPG is harder (in my opinion) that saving data for an RTS. How I do it in my most recent game (an RTS) is what I like to call saving the state. A player can not save in the middle of a battle (other games allow you to, I don't because it is easier) so the only data I have to save is player information, like hours played, times won / lost, a score (if i want there to be one) and what level in the campaign they are currently at. That is it! All of this data is saved as bytes in a txt file.

My code never has bugs... it just develops unexpected features!
Offline ReBirth
« Reply #4 - Posted 2012-08-19 02:20:12 »

Make it per stage/level checkpoint, then you only need to store what the player had when they reached that checkpoint.

Offline DrewLols

Senior Devvie

Medals: 4
Projects: 1

Noob going through metamorphosis...

« Reply #5 - Posted 2012-08-23 14:48:15 »

Man, I recently made a thread like this.  I ended up implementing a HashMap and writing it to a file.  I used Serializables, although apparently there are some alternatives that are more effective than Java's built in Serialization.  The save data might be something like...

public class SaveData
    private HashMap saveData<String, Serializable>;

    public void addProperty(String key, Serializable value)
        saveData.put(key, value);

    public void removeProperty(String key)

    // I don't feel like writing this.  Just know that you can use an ObjectOutputStream to write a Serializable object to a file, and an ObjectInputStream
    // to read an object from a file.  It should save the Object as it is so long as you did everything right.  I recommend looking up how to use the
    // Serializable Interface.  In conclusion, you'd be planning to write the HashMap to a file.
    public void save()

    // Yeah, use an ObjectInputStream to read the HashMap into the SaveData if it exists.  Otherwise, make a new HashMap
    public void load()

Keep in mind that not everything about an object can be serialized.  The attributes of an object will become Serialized along with the object so long as they either implement the Serializable Interface, or are of a primitive data type.  A HashMap implements the Serializable interface, so it is fair game.

Yeah, and this code won't run...  Haven't tested it.  Just demonstrates.

Did you know that 90% of statistics are wrong?
Offline Sonic96PL

Senior Newbie

« Reply #6 - Posted 2012-08-23 19:51:14 »

Thanks, that's what I was looking for.

Pages: [1]
  ignore  |  Print  

EgonOlsen (74 views)
2018-06-10 19:43:48

EgonOlsen (55 views)
2018-06-10 19:43:44

EgonOlsen (74 views)
2018-06-10 19:43:20

DesertCoockie (254 views)
2018-05-13 18:23:11

nelsongames (154 views)
2018-04-24 18:15:36

nelsongames (154 views)
2018-04-24 18:14:32

ivj94 (895 views)
2018-03-24 14:47:39

ivj94 (156 views)
2018-03-24 14:46:31

ivj94 (808 views)
2018-03-24 14:43:53

Solater (172 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!