所以我的LibGDX项目在桌面和Android上运行完全正常,但是当我实现一个测量玩家得分的浮点数时,游戏将在android上崩溃。这个想法是每次屏幕向上滚动时分数会降低,而当屏幕向下滚动时分数会增加。我正在使用gesturedetector控制器进行滚动。 这是主要代码:
public class WorldScreen implements Screen{
private Texture bgCity;
private Texture bgLoop;
private Texture hud;
public static OrthographicCamera camera;
SpriteBatch batch;
Rectangle player;
Rectangle background;
Rectangle backgroundloop;
public float camx = 0;
public float camy = 0;
public static float score = 384400000;
GestureListenerC controller;
public WorldScreen(final JetpackGame aa) {
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camx = camera.viewportWidth / 2f;
camy = camera.viewportHeight / 2f;
controller.update();
camera.update();
batch.setProjectionMatrix(camera.combined);
batch.begin();
batch.draw(bgCity, background.x, background.y);
if(background.y <= -3296){
if(backgroundloop.y <= -800) backgroundloop.y = 0;
}
if(camy >= 100) batch.draw(bgLoop, backgroundloop.x, backgroundloop.y);
if(camera.position.y >= 5360) camera.position.y = 4420;
batch.end();
}
@Override
public void resize(int width, int height) {
}
@Override
public void show() {
controller = new GestureListenerC();
GestureDetector gestureDetector = new GestureDetector(20, 0.5f, 2, 0.15f, controller);
Gdx.input.setInputProcessor(gestureDetector);
bgCity = new Texture(Gdx.files.internal("img/city_BG.png"));
bgLoop = new Texture(Gdx.files.internal("img/loopBG.png"));
hud = new Texture(Gdx.files.internal("img/hud.png"));
camera = new OrthographicCamera();
camera.setToOrtho(false, 420,800);
batch = new SpriteBatch();
player = new Rectangle();
player.x = 420/2;
player.y = 800/2;
background = new Rectangle();
background.x = 0;
background.y = 0;
background.width = 479;
background.height = 4096;
backgroundloop = new Rectangle();
backgroundloop.x = 0;
backgroundloop.y = 4096;
backgroundloop.width = 512;
backgroundloop.height = 1024;
}
@Override
public void hide() {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
batch.dispose();
bgCity.dispose();
bgLoop.dispose();
hud.dispose();
}
}
And here is the controller class:
public class GestureListenerC implements GestureListener{
public static float velX, velY;
public static boolean flinging = false;
float initialScale = 1;
public boolean touchDown (float x, float y, int pointer, int button) {
flinging = false;
return false;
}
@Override
public boolean tap (float x, float y, int count, int button) {
return false;
}
@Override
public boolean longPress (float x, float y) {
return false;
}
@Override
public boolean fling (float velocityX, float velocityY, int button) {
flinging = true;
velX = WorldScreen.camera.zoom * velocityX * 0.5f;
velY = WorldScreen.camera.zoom * velocityY * 0.5f;
return false;
}
@Override
public boolean pan (float x, float y, float deltaX, float deltaY) {
WorldScreen.camera.position.y += deltaY;
WorldScreen.score -= deltaY;
return false;
}
@Override
public boolean panStop (float x, float y, int pointer, int button) {
return false;
}
@Override
public boolean zoom (float originalDistance, float currentDistance) {
return false;
}
@Override
public boolean pinch (Vector2 initialFirstPointer, Vector2 initialSecondPointer, Vector2 firstPointer, Vector2 secondPointer) {
return false;
}
public void update () {
if (flinging) {
velY *= 0.98f;
WorldScreen.score -= 0.2f * velY;
WorldScreen.camera.position.add(0, velY * Gdx.graphics.getDeltaTime(), 0);
if (Math.abs(velY) < 0.01f) velY = 0;
}
}
}
这是logcat在使用模拟器运行后所说的内容:(我不喜欢使用它,因为它经常因模拟器图形问题而崩溃。)
01-21 10:01:37.982: W/dalvikvm(274): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-21 10:01:38.002: E/AndroidRuntime(274): FATAL EXCEPTION: main
01-21 10:01:38.002: E/AndroidRuntime(274): java.lang.RuntimeException: Unable to start activityy ComponentInfo{com.vahlaville.game.android/com.vahlaville.game.android.AndroidLauncher}: com.badlogic.gdx.utils.GdxRuntimeException: Libgdx requires OpenGL ES 2.0
01-21 10:01:38.002: E/AndroidRuntime(274): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-21 10:01:38.002: E/AndroidRuntime(274): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-21 10:01:38.002: E/AndroidRuntime(274): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-21 10:01:38.002: E/AndroidRuntime(274): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-21 10:01:38.002: E/AndroidRuntime(274): at android.os.Handler.dispatchMessage(Handler.java:99)
01-21 10:01:38.002: E/AndroidRuntime(274): at android.os.Looper.loop(Looper.java:123)
01-21 10:01:38.002: E/AndroidRuntime(274): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-21 10:01:38.002: E/AndroidRuntime(274): at java.lang.reflect.Method.invokeNative(Native Method)
01-21 10:01:38.002: E/AndroidRuntime(274): at java.lang.reflect.Method.invoke(Method.java:521)
01-21 10:01:38.002: E/AndroidRuntime(274): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-21 10:01:38.002: E/AndroidRuntime(274): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-21 10:01:38.002: E/AndroidRuntime(274): at dalvik.system.NativeStart.main(Native Method)
01-21 10:01:38.002: E/AndroidRuntime(274): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Libgdx requires OpenGL ES 2.0
01-21 10:01:38.002: E/AndroidRuntime(274): at com.badlogic.gdx.backends.android.AndroidGraphics.createGLSurfaceView(AndroidGraphics.java:122)
01-21 10:01:38.002: E/AndroidRuntime(274): at com.badlogic.gdx.backends.android.AndroidGraphics.<init>(AndroidGraphics.java:102)
01-21 10:01:38.002: E/AndroidRuntime(274): at com.badlogic.gdx.backends.android.AndroidGraphics.<init>(AndroidGraphics.java:95)
01-21 10:01:38.002: E/AndroidRuntime(274): at com.badlogic.gdx.backends.android.AndroidApplication.init(AndroidApplication.java:133)
01-21 10:01:38.002: E/AndroidRuntime(274): at com.badlogic.gdx.backends.android.AndroidApplication.initialize(AndroidApplication.java:99)
01-21 10:01:38.002: E/AndroidRuntime(274): at com.vahlaville.game.android.AndroidLauncher.onCreate(AndroidLauncher.java:18)
01-21 10:01:38.002: E/AndroidRuntime(274): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-21 10:01:38.002: E/AndroidRuntime(274): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-21 10:01:38.002: E/AndroidRuntime(274): ... 11 more
答案 0 :(得分:1)
GdxRuntimeException:Libgdx需要OpenGL ES 2.0
确保在你的`AndroidManifest.xml:
中有这个<uses-feature android:glEsVersion="0x00020000" android:required="true" />
如果这样做,则表示您的设备没有libgdx
必需的OpenGL ES v2。