[英]Sprite class not drawn when using Sprite.draw(batch) LibGDX
我试图显示使用Sprite类缩放的纹理。 问题是当我尝试运行代码时。 我可以在Android 4.1中显示纹理,但是当我在另一个Android中运行相同的程序(例如2.2、2.3.6)时,不会显示Sprite。 这是我的代码。
public void render() {
// TODO Auto-generated method stub
Gdx.gl10.glClearColor(1, 0.4f, 0.3f, 1);
Gdx.gl10.glClear(GL10.GL_COLOR_BUFFER_BIT);
if(estadojuego==0){
batch.begin();
sboton1.draw(batch);
sboton2.draw(batch);
batch.end();
if(Gdx.input.isTouched()){
System.out.println("x"+Gdx.input.getX());
System.out.println("y"+Gdx.input.getY());
if(Gdx.input.getY()<(altura-posicion1.y) && Gdx.input.getY()>(altura-(posicion1.y+posicion1.height))){
if(Gdx.input.getX()<(posicion1.x+posicion1.width) && Gdx.input.getX()>posicion1.x){
//estadojuego=1;
System.out.println("boton1");
}
if(Gdx.input.getX()<(posicion2.x+posicion2.width) && Gdx.input.getX()>posicion2.x){
estadojuego=2;
}
}
}
}
if(estadojuego==2){
batch.begin();
sboton3.draw(batch);
batch.end();
if(Gdx.input.isTouched()){
if(Gdx.input.getY()<(altura-posicion3.y) && Gdx.input.getY()>(altura-(posicion3.y+posicion3.height))){
if(Gdx.input.getX()<(posicion3.x+posicion3.width) && Gdx.input.getX()>posicion3.x){
estadojuego=0;
}
}
}
}
}
非常感谢,抱歉我的英语不好。
似乎您没有为批次设置Matrix4 。
用这个 :
private Matrix4 Projection;
在create()中 :
Projection = new Matrix4().setToOrtho2D(0, 0, (float) Gdx.graphics.getWidth(), (float) Gdx.graphics.getHeight());
在batch.begin之前渲染()();
batch.setProjectionMatrix(Projection);
希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.