سؤال

لقد وجدت أنه بعد استئناف اللعبة يتم إعادة تحميل جميع المحرك وتطبيقه إعادة هياكل. أريد حفظ حالة المحرك وفي "OnResume" استئناف لعبة Proccess.

لقد حاولت حفظ جميع المحرك (Mengine) ثم بعد استئناف اللعبة في المحرك المحفوظ "Onloadengine".أعتقد أنه حل سيء ولا يعمل

ما هو أفضل حل للإيقاف المؤقت \ استئناف اللعبة (بعد الضغط على مفتاح الطاقة على سبيل المثال) في Andengine؟

هل كانت مفيدة؟

المحلول

The solution I found was to serialize the state of the engine as JSON and save it as shared storage. Its a lot of work, but it does save it. Since andengine is going to re-init your engine and textures after a pause, I think there are not many choices, unless you want to re-write some of andengine for your game. (which you can)

In my JSON I record the position type velocity etc of each sprite. The complexity of what gets saved depends on the complexity of your game. And then to each class I added a deserialize method that accepts the JSON as input.

As a footnote to that method, I cannot speak highly enough of the amazing GSON library for making that an easier task. http://code.google.com/p/google-gson/

But remeber when restoring the game, to set the restored state to paused so the user knows when the game will re-commence.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top