尝试使用libGDX进行编码时出错

时间:2015-05-28 04:06:21

标签: java android libgdx


我正在尝试使用libGDX开发一款新游戏。
由于我是libGDX的初学者,我首先尝试在屏幕上显示图像。 我已经按照教程编写了相应的代码,但是我收到了一个错误"不幸的是,已经停止"
我的错误logcat是: -

05-28 09:20:10.740: E/memtrack(581): Couldn't load memtrack module (No such file or directory)
05-28 09:20:10.740: E/android.os.Debug(581): failed to load memtrack module: -2
05-28 09:20:13.560: E/cutils-trace(581): Error opening trace file: No such file or directory (2)
05-28 09:20:13.580: E/cutils-trace(1707): Error opening trace file: No such file or directory (2)
05-28 09:20:19.680: E/EmojiFactory_jni(581): Failed to load libemoji.so: dlopen failed: library "libemoji.so" not found
05-28 09:41:43.130: E/cutils-trace(1745): Error opening trace file: No such file or directory (2)
05-28 09:41:43.170: E/memtrack(1745): Couldn't load memtrack module (No such file or directory)
05-28 09:41:43.170: E/android.os.Debug(1745): failed to load memtrack module: -2


配置代码是: -

package com.mygdx.game.android;

import android.os.Bundle;

import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;


public class AndroidLauncher extends AndroidApplication {
    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();

        initialize(new MyDemo(), config);
    }
}

<小时/> MyDemo.java的代码: -

package com.mygdx.game.android;
import javax.microedition.khronos.opengles.GL10;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import android.app.Application;


public class MyDemo
implements ApplicationListener{
private OrthographicCamera camera;
private Texture texture;
private TextureRegion tr;
private Sprite s;
private SpriteBatch sb;
    public MyDemo() {
        // TODO Auto-generated constructor stub
    }

    @Override
    public void create() {
        // TODO Auto-generated method stub
        float w=Gdx.graphics.getWidth();
        float h=Gdx.graphics.getHeight();
        camera=new OrthographicCamera(1,h/w);
        sb=new SpriteBatch();
        texture=new Texture(Gdx.files.internal(("data/badlogic.jpg")));
        texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
        s=new Sprite(texture);
        s.setSize(0.9f, 0.9f*s.getHeight()/s.getWidth());
        s.setOrigin(s.getWidth()/2, s.getHeight()/2);
        s.setPosition(-s.getWidth()/2,-s.getHeight()/2);
    }

    @Override
    public void dispose() {
        // TODO Auto-generated method stub
        sb.dispose();
        texture.dispose();
    }

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

    }

    @Override
    public void render() {
        // TODO Auto-generated method stub
        Gdx.gl.glClearColor(1, 1, 1, 1);
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
        sb.setProjectionMatrix(camera.combined);
        sb.begin();
        s.draw(sb);
        sb.end();
    }

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

    }

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

    }

}


我把badlogic.jpg文件放在assets文件夹中 请帮帮我! 在此先感谢。

1 个答案:

答案 0 :(得分:1)

这两个进口没有意义:

import javax.microedition.khronos.opengles.GL10;
import android.app.Application;

如果它们是核心项目中的有效导入,则可能添加了生成错误的库。您应该只能使用此导入:

import com.badlogic.gdx.graphics.GL20;