libGDX动画的android [英] libGDX animation for android

查看:128
本文介绍了libGDX动画的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我先干为桌面运行pretty的不错,但它崩溃出口为我以后的And​​r​​oid之后我启动应用程序。

If I start it for Desktop it runs pretty nice, but after the export for my Android it crashes right after I start the application.

所以我的问题...

什么是错的,它适用于桌面,但不是我的Andr​​oid?

What's wrong that it works for the Desktop but not for my Android?

public class Player implements Serializable{

/**
 * 
 */
private static final long serialVersionUID = -7913517465400462738L;

Vector2 position;
private static final int col = 4;
private static final int row = 4;
private Animation animation;
private Texture playerTexture;
private TextureRegion[] frames;
private TextureRegion currentFrame;
private float stateTime;
private int x,y, deltaX, deltaY;



public Player(Vector2 position){
    this.position = position;
    playerTexture = new Texture(Gdx.files.internal("Charackter/charackter_sprite.png"));
    TextureRegion[][] temp = TextureRegion.split(playerTexture, playerTexture.getWidth() / col, playerTexture.getHeight() / row);
    frames = new TextureRegion[col* row];

    int index = 0;
    for(int i = 0; i < row; i++){
        for(int j = 0; j < col; j++){
            frames[index++] = temp[i][j];
        }
    }
    animation = new Animation(1, frames);
    stateTime = 0;
    currentFrame = animation.getKeyFrame(0);
    deltaX = Gdx.graphics.getWidth();
    deltaY = Gdx.graphics.getHeight();
}

public void update(){

    if(stateTime < 4){
    stateTime += Gdx.graphics.getDeltaTime();
    }
    else{
        stateTime = 0;
    }       

    if (Gdx.input.isTouched())
    {
        x = Gdx.input.getX();
        y = Gdx.input.getY();
        if(x < deltaX * 50 / 100 && y > deltaY * 35 / 100 && y < deltaY * 65 / 100){
            position.x -= 1;
            currentFrame = animation.getKeyFrame(4 + stateTime);
        }
        if(x > deltaX * 50 / 100 && y > deltaY * 35 / 100 && y < deltaY * 65 / 100){
            position.x += 1;
            currentFrame = animation.getKeyFrame(8 + stateTime);
        }
        if(y < deltaY * 35 / 100 ){
            position.y += 1;
            currentFrame = animation.getKeyFrame(12 + stateTime);
        }
        if(y > deltaY * 65 / 100 ){
            position.y -= 1;
            currentFrame = animation.getKeyFrame(0 + stateTime);
        }
    }
}


public Vector2 getPosition() {
    return position;
}
public void setPosition(Vector2 position) {
    this.position = position;
}
public TextureRegion getCurrentFrame() {
    return currentFrame;
}
}

public class PlayScreen implements Screen {

private SpriteBatch batch;
private Vector2 position;
private Game game;
private Player player;
private Texture bild;

public PlayScreen(Game game){
    this.game = game;
}

@Override
public void render(float delta) {       
    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    player.update();
    batch.begin();
    batch.draw(player.getCurrentFrame(), player.getPosition().x, player.getPosition().y);
    batch.end();
}

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

}

@Override
public void show() {
    batch = new SpriteBatch();
    position = new Vector2(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
    player = new Player(position);
    bild = new Texture("spongebob.png");
}

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

}

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

}

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

}

@Override
public void dispose() {
    batch.dispose();

}

}

logcat的

Logcat

11-25 11:25:20.990: D/dalvikvm(862): Trying to load lib /data/app-lib/com.mygdx.game.android-2/libgdx.so 0xb1caad50
11-25 11:25:21.040: D/dalvikvm(862): Added shared lib /data/app-lib/com.mygdx.game.android-2/libgdx.so 0xb1caad50
11-25 11:25:21.040: D/dalvikvm(862): No JNI_OnLoad found in /data/app-lib/com.mygdx.game.android-2/libgdx.so 0xb1caad50, skipping init
11-25 11:25:21.100: D/AndroidRuntime(862): Shutting down VM
11-25 11:25:21.100: W/dalvikvm(862): threadid=1: thread exiting with uncaught exception (group=0xb1a73d70)
11-25 11:25:21.110: E/AndroidRuntime(862): FATAL EXCEPTION: main
11-25 11:25:21.110: E/AndroidRuntime(862): Process: com.mygdx.game.android, PID: 862
11-25 11:25:21.110: E/AndroidRuntime(862): 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
11-25 11:25:21.110: E/AndroidRuntime(862):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
11-25 11:25:21.110: E/AndroidRuntime(862):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
11-25 11:25:21.110: E/AndroidRuntime(862):  at android.app.ActivityThread.access$800(ActivityThread.java:138)
11-25 11:25:21.110: E/AndroidRuntime(862):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
11-25 11:25:21.110: E/AndroidRuntime(862):  at android.os.Handler.dispatchMessage(Handler.java:102)
11-25 11:25:21.110: E/AndroidRuntime(862):  at android.os.Looper.loop(Looper.java:136)
11-25 11:25:21.110: E/AndroidRuntime(862):  at android.app.ActivityThread.main(ActivityThread.java:5026)
11-25 11:25:21.110: E/AndroidRuntime(862):  at java.lang.reflect.Method.invokeNative(Native Method)
11-25 11:25:21.110: E/AndroidRuntime(862):  at java.lang.reflect.Method.invoke(Method.java:515)
11-25 11:25:21.110: E/AndroidRuntime(862):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
11-25 11:25:21.110: E/AndroidRuntime(862):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
11-25 11:25:21.110: E/AndroidRuntime(862):  at dalvik.system.NativeStart.main(Native Method)
11-25 11:25:21.110: E/AndroidRuntime(862): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Libgdx requires OpenGL ES 2.0
11-25 11:25:21.110: E/AndroidRuntime(862):  at com.badlogic.gdx.backends.android.AndroidGraphics.createGLSurfaceView(AndroidGraphics.java:122)
11-25 11:25:21.110: E/AndroidRuntime(862):  at com.badlogic.gdx.backends.android.AndroidGraphics.<init>(AndroidGraphics.java:102)
11-25 11:25:21.110: E/AndroidRuntime(862):  at com.badlogic.gdx.backends.android.AndroidGraphics.<init>(AndroidGraphics.java:95)
11-25 11:25:21.110: E/AndroidRuntime(862):  at com.badlogic.gdx.backends.android.AndroidApplication.init(AndroidApplication.java:133)
11-25 11:25:21.110: E/AndroidRuntime(862):  at com.badlogic.gdx.backends.android.AndroidApplication.initialize(AndroidApplication.java:99)
11-25 11:25:21.110: E/AndroidRuntime(862):  at com.mygdx.game.android.AndroidLauncher.onCreate(AndroidLauncher.java:14)
11-25 11:25:21.110: E/AndroidRuntime(862):  at android.app.Activity.performCreate(Activity.java:5242)
11-25 11:25:21.110: E/AndroidRuntime(862):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-25 11:25:21.110: E/AndroidRuntime(862):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
11-25 11:25:21.110: E/AndroidRuntime(862):  ... 11 more

我是pretty的新Java中 所以我希望这是正确的部分:X

I'm pretty new in Java so I hope it's the right part :x

推荐答案

已经有一些人有例外,其中的logcat说:

There has been some persons with exceptions where the logcat says:

GdxRuntimeException: Libgdx requires OpenGL ES 2.0   

这是因为你的模拟器不使用GPU进行图形和最好的解决办法是使用手机来测试你的应用程序,但如果因为任何原因,你不能,你可以为@AngelAngel应用该解决方案:的 libgdx Android的失败上推出
出于某种原因(可能不是失灵了OpenGL)的解决方案,以下面的错误也可以帮助你。

This is due to your emulator not using your gpu for graphics and the best solution would be to use your phone to test your application but if for any reason you can't you can as @AngelAngel apply this solution: libgdx android failed on launch.
For some reason ( probably the opengl not glitching ) the solution to the following error might also help you

 com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: xxx.xxx

如果你有这样的误差仅在Android中尝试,而它在Windows上运行,它可能是因为你的资产之一,并不完全是你用你的code中的名称相匹配。 Unix的区分sensative所以image.jpg的是image.jpg的不同。因此,检查所有的资产,你必须看到,如果名称相匹配!

If you have this error only while experimenting in Android while it works on Windows it probably is because one of your assets doesn't exactly match the name you used on your code. Unix is case-sensative so image.jpg is different from Image.jpg . So check every asset you have to see if the names match!

这篇关于libGDX动画的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆