How to create a save feature for JavaFX game? -
i making simple game using javafx. old pokemon game, want make save/load features users can continue game after reboot computer.
this question bit broad; long you're on javafx 8, suggest looking nio.2 tutorial. it's recent of i/o apis, , designed rapidity. specifically, paths , files classes have methods allow swiftly save data file, , read out.
for formats, since you're not accustomed file i/o, keep simple can. it's best label data, not store in binary; sake of versatility , flexibility later on. (a minor change in game shouldn't invalidate entire file format.)
as example, might reference file with:
string dir = ...; string name = ...; path savepath = paths.get(dir + file.separator + name); once have path, use:
bufferedwriter writer = files.newbufferedwriter(savepath, standardopenoption.create); from there, can use bufferedwriter write data can use system.out. sure check javadoc, there quite few methods aware of. save time. likewise, there's newbufferedreader method can use, through same code, read file.
lastly, recommend staying away older io , nio options have been broadly replaced; , when need "\" or "/" (depending on operating system), use system property file.separator or static field file.separator; splicing characters in literally break program on other operating systems, , kill original point of using java.
this broad answer broad question, hope i've gotten on right track. let me know if there's confusion.
Comments
Post a Comment