Libgdx程序在桌面上运行但在Android上运行

时间:2014-12-09 23:50:07

标签: java android libgdx

我从libgdx获得的测试程序在Android上运行,所以我认为它不能是ADT-Plugin或类似的东西。我没有更改Android代码中的任何内容,这是我的核心代码:

package com.mygdx.game;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;

public class MyGdxGame extends Game {
Stage stage;
private Skin skin;
private TextButton buttonPlay;
private Image red;
private Image green;
Boolean move=false;


@Override
public void create () {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    skin = new Skin(Gdx.files.internal("button.json"),
                new TextureAtlas(Gdx.files.internal("ButtonSkins/menu.pack")));
    buttonPlay = new TextButton("Start", skin);

    red = new Image (new Texture("ButtonSkins/menu_hintergrund.png"));
    green = new Image (new Texture("ButtonSkins/menu_hintergrund2.png"));
    red.setHeight(stage.getHeight()/2);
    red.setWidth(stage.getWidth());
    green.setHeight(stage.getHeight()/2);
    green.setWidth(stage.getWidth());
    green.setPosition(0, stage.getHeight()/2);
    buttonPlay.setWidth((float) (red.getWidth()/2.45));
    stage.addActor(red);
    stage.addActor(green);
    stage.addActor(buttonPlay);
    buttonPlay.moveBy(stage.getWidth()/2-buttonPlay.getWidth()/2, stage.getHeight()/2-buttonPlay.getHeight()/2);
    buttonPlay.addListener(new ChangeListener(){
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            move=true;
        }           
        });
}

@Override
public void render () {
    Gdx.gl.glClearColor(150,110, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    if(move){
    green.addAction(Actions.sequence(Actions.moveBy(0, 5)));
    red.addAction(Actions.sequence(Actions.moveBy(0, -5)));
    }
    stage.act();
    stage.draw();
}

@Override
public void dispose() {
    stage.dispose();
}

}

我真的不知道我做错了能有人帮助我吗?

目录下载:

12-10 00:22:45.920: D/dalvikvm(725): Not late-enabling CheckJNI (already on)

12-10 00:22:47.940: D/dalvikvm(725): Trying to load lib /data/app-lib/com.mygdx.game.android-1/libgdx.so 0xb2c83e88

12-10 00:22:47.940: D/dalvikvm(725): Added shared lib /data/app-lib/com.mygdx.game.android-1/libgdx.so 0xb2c83e88

12-10 00:22:47.940: D/dalvikvm(725): No JNI_OnLoad found in /data/app-lib/com.mygdx.game.android-1/libgdx.so 0xb2c83e88, skipping init

12-10 00:22:48.210: D/AndroidRuntime(725): Shutting down VM

12-10 00:22:48.210: W/dalvikvm(725): threadid=1: thread exiting with uncaught exception (group=0xb2a80d70)

12-10 00:22:48.260: E/AndroidRuntime(725): FATAL EXCEPTION: main

12-10 00:22:48.260: E/AndroidRuntime(725): Process: com.mygdx.game.android, PID: 725

12-10 00:22:48.260: E/AndroidRuntime(725): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mygdx.game.android/com.mygdx.game.android.AndroidLauncher}: com.badlogic.gdx.utils.GdxRuntimeException: Libgdx requires OpenGL ES 2.0

12-10 00:22:48.260: E/AndroidRuntime(725):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)

12-10 00:22:48.260: E/AndroidRuntime(725):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)

12-10 00:22:48.260: E/AndroidRuntime(725):  at android.app.ActivityThread.access$800(ActivityThread.java:138)

12-10 00:22:48.260: E/AndroidRuntime(725):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)

12-10 00:22:48.260: E/AndroidRuntime(725):  at android.os.Handler.dispatchMessage(Handler.java:102)

12-10 00:22:48.260: E/AndroidRuntime(725):  at android.os.Looper.loop(Looper.java:136)

12-10 00:22:48.260: E/AndroidRuntime(725):  at android.app.ActivityThread.main(ActivityThread.java:5026)

12-10 00:22:48.260: E/AndroidRuntime(725):  at java.lang.reflect.Method.invokeNative(Native Method)

12-10 00:22:48.260: E/AndroidRuntime(725):  at java.lang.reflect.Method.invoke(Method.java:515)

12-10 00:22:48.260: E/AndroidRuntime(725):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)

12-10 00:22:48.260: E/AndroidRuntime(725):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)

12-10 00:22:48.260: E/AndroidRuntime(725):  at dalvik.system.NativeStart.main(Native Method)

12-10 00:22:48.260: E/AndroidRuntime(725): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Libgdx requires OpenGL ES 2.0

12-10 00:22:48.260: E/AndroidRuntime(725):  at com.badlogic.gdx.backends.android.AndroidGraphics.createGLSurfaceView(AndroidGraphics.java:122)

12-10 00:22:48.260: E/AndroidRuntime(725):  at com.badlogic.gdx.backends.android.AndroidGraphics.<init>(AndroidGraphics.java:102)

12-10 00:22:48.260: E/AndroidRuntime(725):  at com.badlogic.gdx.backends.android.AndroidGraphics.<init>(AndroidGraphics.java:95)

12-10 00:22:48.260: E/AndroidRuntime(725):  at com.badlogic.gdx.backends.android.AndroidApplication.init(AndroidApplication.java:133)

12-10 00:22:48.260: E/AndroidRuntime(725):  at com.badlogic.gdx.backends.android.AndroidApplication.initialize(AndroidApplication.java:99)

12-10 00:22:48.260: E/AndroidRuntime(725):  at com.mygdx.game.android.AndroidLauncher.onCreate(AndroidLauncher.java:14)

12-10 00:22:48.260: E/AndroidRuntime(725):  at android.app.Activity.performCreate(Activity.java:5242)

12-10 00:22:48.260: E/AndroidRuntime(725):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)

12-10 00:22:48.260: E/AndroidRuntime(725):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)

12-10 00:22:48.260: E/AndroidRuntime(725):  ... 11 more

12-10 00:23:36.730: D/dalvikvm(844): Trying to load lib /data/app-lib/com.mygdx.game.android-2/libgdx.so 0xb2c85d70

12-10 00:23:36.750: D/dalvikvm(844): Added shared lib /data/app-lib/com.mygdx.game.android-2/libgdx.so 0xb2c85d70

12-10 00:23:36.760: D/dalvikvm(844): No JNI_OnLoad found in /data/app-lib/com.mygdx.game.android-2/libgdx.so 0xb2c85d70, skipping init

12-10 00:23:36.830: D/AndroidRuntime(844): Shutting down VM

12-10 00:23:36.840: W/dalvikvm(844): threadid=1: thread exiting with uncaught exception (group=0xb2a80d70)

12-10 00:23:36.900: E/AndroidRuntime(844): FATAL EXCEPTION: main

12-10 00:23:36.900: E/AndroidRuntime(844): Process: com.mygdx.game.android, PID: 844

12-10 00:23:36.900: E/AndroidRuntime(844): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mygdx.game.android/com.mygdx.game.android.AndroidLauncher}: com.badlogic.gdx.utils.GdxRuntimeException: Libgdx requires OpenGL ES 2.0

12-10 00:23:36.900: E/AndroidRuntime(844):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)

12-10 00:23:36.900: E/AndroidRuntime(844):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)

12-10 00:23:36.900: E/AndroidRuntime(844):  at android.app.ActivityThread.access$800(ActivityThread.java:138)

12-10 00:23:36.900: E/AndroidRuntime(844):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)

12-10 00:23:36.900: E/AndroidRuntime(844):  at android.os.Handler.dispatchMessage(Handler.java:102)

12-10 00:23:36.900: E/AndroidRuntime(844):  at android.os.Looper.loop(Looper.java:136)

12-10 00:23:36.900: E/AndroidRuntime(844):  at android.app.ActivityThread.main(ActivityThread.java:5026)

12-10 00:23:36.900: E/AndroidRuntime(844):  at java.lang.reflect.Method.invokeNative(Native Method)

12-10 00:23:36.900: E/AndroidRuntime(844):  at java.lang.reflect.Method.invoke(Method.java:515)

12-10 00:23:36.900: E/AndroidRuntime(844):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)

12-10 00:23:36.900: E/AndroidRuntime(844):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)

12-10 00:23:36.900: E/AndroidRuntime(844):  at dalvik.system.NativeStart.main(Native Method)

12-10 00:23:36.900: E/AndroidRuntime(844): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Libgdx requires OpenGL ES 2.0

12-10 00:23:36.900: E/AndroidRuntime(844):  at com.badlogic.gdx.backends.android.AndroidGraphics.createGLSurfaceView(AndroidGraphics.java:122)

12-10 00:23:36.900: E/AndroidRuntime(844):  at com.badlogic.gdx.backends.android.AndroidGraphics.<init>(AndroidGraphics.java:102)

12-10 00:23:36.900: E/AndroidRuntime(844):  at com.badlogic.gdx.backends.android.AndroidGraphics.<init>(AndroidGraphics.java:95)

12-10 00:23:36.900: E/AndroidRuntime(844):  at com.badlogic.gdx.backends.android.AndroidApplication.init(AndroidApplication.java:133)

12-10 00:23:36.900: E/AndroidRuntime(844):  at com.badlogic.gdx.backends.android.AndroidApplication.initialize(AndroidApplication.java:99)

12-10 00:23:36.900: E/AndroidRuntime(844):  at com.mygdx.game.android.AndroidLauncher.onCreate(AndroidLauncher.java:14)

12-10 00:23:36.900: E/AndroidRuntime(844):  at android.app.Activity.performCreate(Activity.java:5242)

12-10 00:23:36.900: E/AndroidRuntime(844):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)

12-10 00:23:36.900: E/AndroidRuntime(844):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)

12-10 00:23:36.900: E/AndroidRuntime(844):  ... 11 more

1 个答案:

答案 0 :(得分:0)

如果您使用模拟器测试您不应该,但如果您无法使用手机进行测试,可以尝试:libgdx android failed on launch

也可能是你在Windows中测试桌面并且外部目录或文件名没有匹配,在Windows中不会造成任何麻烦,但在Unix中,文件名和目录名是案件敏感所以Teste.jpg与teste.jpg不同

来源:https://stackoverflow.com/a/27125547/1779833