0

So my LibGDX project works completely fine on desktop and on android too, but when I implement a float which measures the players score, the game will crash on android. The idea is that the score will decrease every time the screen is scrolled upwards and increase when it's scrolled downwards. I'm using gesturedetector controller for the scrolling. Here is the main code:

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;
        }
    }
}

This is what logcat says after running it with an emulator: (I don't prefer using it because it often crashes due to emulators graphic problems.)

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
4
  • Crash should mean logcat stacktrace, right? Please post it. Commented Jan 21, 2015 at 9:30
  • I added the logcat messages. However I don't know if they are helpful because the game often crashes with the emulator due to graphic problems which do not encounter on a physical device. Commented Jan 21, 2015 at 10:09
  • If you look at that stack trace, the crash is due to the emulator not supporting OpenGL ES 2.0, so it's not relevant to your actual problem. Commented Jan 21, 2015 at 13:45
  • The stactrace is not telling pretty much anything, because the game crashes on emulator however due graphical problems Commented Jan 22, 2015 at 7:24

1 Answer 1

1

GdxRuntimeException: Libgdx requires OpenGL ES 2.0

Make sure you have this in your `AndroidManifest.xml:

<uses-feature android:glEsVersion="0x00020000" android:required="true" />

If you do, then it means your device does not have OpenGL ES v2, which is required by libgdx.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.