0

我一直在尝试在一个新的 Eclipse 项目中实现没有核心项目的 libgdx,但我不断得到:

AndroidApplication 类型中的方法 initialize(ApplicationListener, AndroidApplicationConfiguration) 不适用于参数 (AndroidApplication, AndroidApplicationConfiguration)

目前我使用的代码非常简单:

package com.debels.androidapplication;

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

import android.os.Bundle;

public class MainActivity extends AndroidApplication{

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
        cfg.useGL20 = false;

        initialize(new AndroidApplication(), cfg);
    }
}

package com.debels.androidapplication;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.FPSLogger;
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 com.debels.androidapplication.screens.MainMenuScreen;

public class AndroidApplication extends Game{
    private OrthographicCamera camera;
    private SpriteBatch batch;
    private Texture texture;
    private Sprite sprite;
    private FPSLogger fps;
    @Override
    public void create(){
        float w = Gdx.graphics.getWidth();
        float h = Gdx.graphics.getHeight();

        camera = new OrthographicCamera(1, h/w);
        batch = new SpriteBatch();

        //texture = new Texture(Gdx.files.internal("data/libgdx.png"));
        //texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);

        //TextureRegion region = new TextureRegion(texture, 0, 0, 512, 275);

        /*sprite = new Sprite(region);
        sprite.setSize(0.9f, 0.9f * sprite.getHeight() / sprite.getWidth());
        sprite.setOrigin(sprite.getWidth()/2, sprite.getHeight()/2);
        sprite.setPosition(-sprite.getWidth()/2, -sprite.getHeight()/2);*/
        setScreen(new MainMenuScreen(this));
        fps = new FPSLogger();

    }

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

    @Override
    public void render() {
        super.render();
        /*fps.log();
        Gdx.gl.glClearColor(1, 1, 1, 1);
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

        batch.setProjectionMatrix(camera.combined);
        batch.begin();
        sprite.draw(batch);
        batch.end();*/
    }

    @Override
    public void resize(int width, int height) {
        super.resize(width, height);
    }

    @Override
    public void pause() {
        super.pause();
    }

    @Override
    public void resume() {
        super.resume();
    }

}
4

1 回答 1

3

那是因为您正在向 ini 发送 (gdx)AndroidApplication 实例而不是 (gdx)AndroidApplicationListener (这是扩展 Game 或实现 ApplicationListener 的任何类)。

你会很困惑,因为你把那个类命名为 AndroidApplication ......

改变这个:

initialize(new AndroidApplication(), cfg);

对此:

initialize(new com.debels.androidapplication.AndroidApplication(), cfg);

或者更好的是,更改该类的名称。另外不要忘记将 gdx.jar 复制到 android 项目 libs 文件夹中。

于 2013-10-11T05:09:01.173 回答