我是 libgdx 的新手,我正在尝试做一些教程。我在加载自己的 .png
文件时遇到问题。
标准项目包含 libgdx.png
文件并且它可以工作。当我在桌面或安卓上运行它时,它工作正常。图像显示良好。
相同的代码,只是另一个文件(也是 png
)。
在桌面版本上运行良好,但无法在 Android 上运行。
我真的不明白发生了什么,因为文件(libgdx.png 和 my.png)位于同一个文件夹中,第一个文件可以在 Android 上运行,但第二个文件不能...
public class AwesomeGame implements ApplicationListener {
SpriteBatch batch;
Texture man;
Texture abc;
Vector2 position;
@Override
public void create() {
batch = new SpriteBatch();
man = new Texture(Gdx.files.internal("my.png"));
position = new Vector2(50,50);
}
@Override
public void dispose() {
}
@Override
public void render() {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
if(Gdx.input.isKeyPressed(Input.Keys.W)){
position.y+=1f;
}
if(Gdx.input.isKeyPressed(Input.Keys.S)){
position.y-=1f;
}
if(Gdx.input.isKeyPressed(Input.Keys.D)){
position.x+=1f;
}
if(Gdx.input.isKeyPressed(Input.Keys.A)){
position.x-=1f;
}
if(Gdx.input.getAccelerometerX()!=0){
position.x-=Gdx.input.getAccelerometerX();
}
if(Gdx.input.getAccelerometerY()!=0){
position.y+=Gdx.input.getAccelerometerY();
}
batch.setColor(position.x,position.y,10,10);
batch.begin();
batch.draw(man, position.y, position.x);
batch.end();
}
有人能给我解释一下吗? ;(
最佳答案
天哪,我明白了。
纹理宽度和高度必须是 2 的幂。
但是如果我设置
cfg.useGL20 = true;
无需 2 的幂即可一切正常。
关于Java libgdx android - 我自己的资源文件未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21948109/