Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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  
  World save system  (Read 1086 times)
0 Members and 1 Guest are viewing this topic.
Offline brian22950

Junior Newbie





« Posted 2012-08-27 20:42:37 »

Hello, i'm new on the forum :p,
I want to do a world save system but i have no idea of how to do this.
I use a sprite system for my game.
Can you help me ?
Thx,
Brian22950

PS : I'm french
Offline DrewLols

Senior Duke


Medals: 3
Projects: 1


Noob going through metamorphosis...


« Reply #1 - Posted 2012-08-28 00:12:19 »

Sort answer:  Learn how to use the Serializable interface in Java

Long answer:

I can only assume that you want to implement save data, correct?  I recommend that you learn how to implement the Serializable interface.  It's basically a way to write objects to a file.  You could make a class that takes in properties and retrieves properties like...


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
SaveData sd = SaveData.getSaveData("saveFile.txt")    // Uses an ObjectInputStream to read an object from a file
if(sd == null)                               // If the getSaveData() method failed, create your save data object
{
    sd = new SaveData();
}

sd.addProperty("hasBanana", "true");                          // Adds a property to your save data object.  The first argument must be a string to identify
                                                                           // what you want, and the object you put in can be anything.  In this case, it's the String value
                                                                           // "true"

sd.save("saveFile.txt");                                            // Uses an ObjectOutputStream to write sd to a file

if(sd.getProperty("hasBanana").equals("true"))
{
    eatBanana();
}


Of course, you'll have to write the SaveData class yourself, but if you wanted to save data for more complicated objects, it is possible.  For instance...

1  
sd.addProperty("inventory", playerInventory);               // You can write in any object so long as it implements the Serializable interface.


Keep in mind that it takes some work to property implement the Serializable interface.  Basically, you'll be adding many Serializable objects that you want to save to an instance of the Serializable class, SaveData.  Then, you can easily write a SaveData to a file.

It is not THAT simple and you should definitely look up how to property use the Serializable interface.

Just remember that you need an ObjectOutputStream to write an Object to a file, and ObjectInputStream to read an Object from a file, and all object being written must implement the Serializable interface.


Oh, and just so you know, there are other ways to write Objects to a file besides using java's built in Serializable interface.  Just felt like mentioning this so no one on this site yells at me.

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

Junior Newbie





« Reply #2 - Posted 2012-08-28 08:17:37 »

ok, that is i wanted to know, thx, but how can i do to save some informations about a block(like a text for a sign block) ?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jonjava
« Reply #3 - Posted 2012-08-28 20:08:48 »

http://www.tutorialspoint.com/java/java_serialization.htm

Offline DrewLols

Senior Duke


Medals: 3
Projects: 1


Noob going through metamorphosis...


« Reply #4 - Posted 2012-08-29 00:13:30 »

ok, that is i wanted to know, thx, but how can i do to save some informations about a block(like a text for a sign block) ?

Can't really tell you EXACTLY how you'll store and retrieve save data, but you should know that the String class implements the Serializable interface.  You can just store the string text in the Serializable object and retrieve it later.

1  
2  
3  
sd.addProperty("AwesomeText", "Read signs.  It's good for you!");  // Stores property
Sign sign = new Sign();  // Makes sign
sign.setText(sd.getProperty("AwesomeText"));  // Assigns text


Just think of the save data as a machine that you can put stuff in, and take stuff out.  If your entire level was Serializable, you COULD write the entire level to the SaveData.  I wouldn't recommend this because it can get a little inflexible.

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

Junior Newbie





« Reply #5 - Posted 2012-08-29 08:41:14 »

Ok, thank you for your quick answers !!
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.

Longarmx (37 views)
2014-10-17 03:59:02

Norakomi (28 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (27 views)
2014-10-15 16:18:58

TehJavaDev (52 views)
2014-10-14 00:39:48

TehJavaDev (54 views)
2014-10-14 00:35:47

TehJavaDev (42 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (77 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!