Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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 1080 times)
0 Members and 1 Guest are viewing this topic.
Offline Sonic96PL

Senior Newbie





« Posted 2012-08-18 20: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.

Greetings,
Sonic96PL
Offline Gjallar

JGO Coder


Medals: 13
Projects: 1


Follower of Nurgle


« Reply #1 - Posted 2012-08-18 20: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 20: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 20: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 04: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 Member


Medals: 1
Projects: 1


Noob going through metamorphosis...


« Reply #5 - Posted 2012-08-23 16: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...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
public class SaveData
{
    private HashMap saveData<String, Serializable>;

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

    public void removeProperty(String key)
    {
        saveData.remove(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 21:51:14 »

Thanks, that's what I was looking for.

Greetings,
Sonic96PL
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (8 views)
2014-07-24 01:59:36

Riven (9 views)
2014-07-23 21:16:32

Riven (11 views)
2014-07-23 21:07:15

Riven (12 views)
2014-07-23 20:56:16

ctomni231 (42 views)
2014-07-18 06:55:21

Zero Volt (38 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (34 views)
2014-07-16 23:30:00

Cero (49 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org 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‑gaming.org
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!