简体   繁体   English

如何创建pygame保存文件

[英]How to create a pygame savefile

I'm creating a game with pygame and I'm still quite new to the programming language. 我正在用pygame创建游戏,但对编程语言还是很陌生。 I tried making data/savefile with file i/o with text file with python (readlines and etc). 我试着用python的文本文件(readlines等)来制作带有文件i / o的数据/保存文件。 I realized, I can't erase a certain line and edit that line with file i/o with text files. 我意识到,我无法删除某一行并无法使用文本文件的文件I / O编辑该行。 So I was wondering how I can create one either with file i/o (another way) or something integrated with pygame maybe? 所以我想知道如何用文件I / O(另一种方式)或与pygame集成的东西创建一个文件?

You should use some kind of serialization where you save your game state (object) in a defined format that you can read in later, so it gets converted to a Python object again. 您应该使用某种序列化,以一种定义的格式保存游戏状态(对象),以便以后阅读,以便将其再次转换为Python对象。 For instance you can use the shelve module or the pickle module for implementing object persistence. 例如,您可以使用shelve模块pickle模块来实现对象持久性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM