如果我从小部件运行,游戏中的图像会在 Android 设备上消失,但在我第一次安装 apk 时不会

In game Images disappear on Android device if i run from widget, but not when I install apk first time(如果我从小部件运行,游戏中的图像会在 Android 设备上消失,但在我第一次安装 apk 时不会)
本文介绍了如果我从小部件运行,游戏中的图像会在 Android 设备上消失,但在我第一次安装 apk 时不会的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我用 LibGDX 创建了一个游戏,它在我的电脑上运行良好.我通过 Gradle View -> Build & 在 Android Studio 中创建了一个调试 .apk然后复制了我的 android-debug.apk &android-debug-unaligned.apk 到我的 Android 设备的下载文件夹.

I created a game in with LibGDX, which works fine on my computer. I created a debug .apk in Android Studio via the Gradle View -> Build & then copied my android-debug.apk & android-debug-unaligned.apk to the download folder of my Android Device.

现在,当我在我的 android 设备上单击我的一个文件时,设备会询问我是否要安装它并选择是,然后我打开我的游戏并且它运行良好.

Now when on my android device I clicked on one of my files the device ask if I wanna install it and choose yes and subsequently I open my game and it run fine.

现在,当我玩完游戏并尝试从安装后放在我的 android-桌面"(包含所有您可以单击的应用程序的主屏幕)上的小部件重新启动游戏时,就会出现问题.

Now the porblem occurs when i quite the game and try to restart the game from the widget that after the installation has been put on my android-"desktop" (main screen with all the apps you can click).

如果我从小部件启动它,我的图形就会混乱和丢失 &我不知道为什么?初始屏幕中缺少徽标图像.切换到 MenuScreen 时,图像丢失.而当我切换到我的游戏画面时,画面就会变得一团糟.

If i start it from the widget my graphics are messed up and missing & i have no idea why? Logo image missing from splashscreen. When switching to MenuScreen the image there is missing. And when I switch to my game screen graphics get totally messed up.

当我重新安装游戏并再次运行时,就没有问题了.

When i re-install the game and run it again, there is no problem.

如果有人可以帮忙?

推荐答案

您的用例的不同之处在于运行您的应用程序的 JVM 的状态.在某些情况下,JVM 是全新的,一切正常.但是,如果JVM被回收(因为Android没有杀死它,只是把它放在后台),你就会遇到问题.问题的核心很可能是,当您重新启动应用程序时,您引用了上次运行的 OpenGL 状态(例如,第一次运行的 OpenGL 纹理 ID 在后续运行中使用).因为 OpenGL 是一个有状态的驱动程序,并且应用程序的状态在失去上下文时会被擦除,所以您需要重新加载全局 OpenGL 状态.

The difference in your use cases is the state of the JVM that is running your application. In some cases the JVM is brand new, and everything works. However, if the JVM is recycled (because Android hasn't killed it, just put it in the background), you run into problems. The core of the problem is, most likely, that you have references to OpenGL state from the previous run when you re-start the application (e.g., OpenGL texture IDs from the first run are getting used on subsequent runs). Because OpenGL is a stateful driver, and an application's state is wiped when it loses context, you need to reload global OpenGL state.

有关底层的描述,请参阅 Android 静态对象生命周期问题和 http://bitiotic.com/blog/2013/05/23/libgdx-and-android-application-lifecycle/ 了解有关诊断和处理它的一些特定于 Libgdx 的提示.

See Android static object lifecycle for a description of the underlying problem and http://bitiotic.com/blog/2013/05/23/libgdx-and-android-application-lifecycle/ for some Libgdx-specific tips on diagnosing and dealing with it.

这篇关于如果我从小部件运行,游戏中的图像会在 Android 设备上消失,但在我第一次安装 apk 时不会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Collision detection between a BoundingBox and a Sphere in libgdx(libgdx 中 BoundingBox 和 Sphere 之间的碰撞检测)
LibGDX blinking(LibGDX 闪烁)
Adding admob underneath game view(在游戏视图下添加 admob)
libGDX: How to implement a smooth tile / grid based game character movement?(libGDX:如何实现基于平铺/网格的游戏角色移动?)
How do I prevent .git directory from getting copied to bin directory during rebuild?(如何防止 .git 目录在重建期间被复制到 bin 目录?)
taking screenshot in libgdx(在 libgdx 中截屏)