无法解析setScreen()方法 [英] Cannot resolve setScreen() method
问题描述
我对libgdx并不陌生,但是当我结束上一个大学项目并开始新的项目时,Android Studio或IDEA无法解析setScreen方法,其他工作正常.有任何想法吗 ?希望能有所帮助. (项目绝对清晰).
I'm not new to libgdx, but when i ended up with my previous university project, and started new one, Android studio or IDEA cannot resolve setScreen method, other stuff works fine. Any ideas ? Hope for help. (project absolutely clear).
推荐答案
在LibGdx中创建项目会为您提供实现ApplicationListener
的核心文件.
Creating a project in LibGdx gives you your core file which implements the ApplicationListener
.
我所指的是在扩展Game
类的同时设置Screen
类.
What I gather you are referring to is extending the Game
class with with you set Screen
classes with.
使用ApplicationListener
.
public class HelloWorld implements ApplicationListener {
private SpriteBatch batch;
private BitmapFont font;
@Override
public void create() {
batch = new SpriteBatch();
font = new BitmapFont();
font.setColor(Color.RED);
}
@Override
public void dispose() {
batch.dispose();
font.dispose();
}
@Override
public void render() {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
batch.begin();
font.draw(batch, "Hello World", 200, 200);
batch.end();
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
}
您要做什么:(摘自 https://github.com/libgdx/libgdx/wiki/扩展简单游戏)
public class Drop extends Game {
public SpriteBatch batch;
public BitmapFont font;
public void create() {
batch = new SpriteBatch();
//Use LibGDX's default Arial font.
font = new BitmapFont();
this.setScreen(new MainMenuScreen(this));
}
public void render() {
super.render(); //important!
}
public void dispose() {
batch.dispose();
font.dispose();
}
}
您可以根据需要更改以下屏幕:
Which allows you to change screens whenever you need:
public class MainMenuScreen implements Screen {
final Drop game;
OrthographicCamera camera;
public MainMenuScreen(final Drop game) {
this.game = game;
camera = new OrthographicCamera();
camera.setToOrtho(false, 800, 480);
}
//...Rest of class omitted for succinctness.
}
这篇关于无法解析setScreen()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!