开发者

How to resolve quickly the pause and resume functions in Libgdx

开发者 https://www.devze.com 2023-03-05 05:18 出处:网络
What code I need to write in the pause() and resume() functions in libgdx for Android? @Override public void create() {

What code I need to write in the pause() and resume() functions in libgdx for Android?

    @Override
    public void create() {
            // TODO Auto-generated method stub

    }

    @Override
    public void dispose() {
            // TODO Auto-generated method stub

    }

    @Override
    public void pause() {
            // TODO Auto-generated method stub

    }

    @Override
    public void render() {
            // TODO Auto-generated method stub

    }

    @Override
    public void resize(int width, int height) {
            // TODO Auto-generated method stub

    }

    @Override
    public void resume() {
           开发者_运维百科 // TODO Auto-generated method stub

    }

}


Basically you do not have to write anything in those two methods. Your libgdx app will work when you setup your app in create() and draw you stuff in render(). This will even work when another activity comes into the foreground and you go back to your libgdx app.

Things change when your libgdx activity is terminated because the system reclaims memory. In that case you can use pause() to save your application state and restore it in resume(). Libgdx does not wrap the Parcelable concept of android yet so you will need to find another persistence mechanism.


pause and resume events that might involve a so-called context loss. When a context loss occurs on Android, it means that the operating system has decided to forcefully free the memory that was occupied with your loaded assets. Therefore, directly accessing your assets after a context loss would immediately crash the resumed game. To prevent these crashes, you need to reload your assets before accessing them again.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号