[英]Sprite class not drawn when using Sprite.draw(batch) LibGDX
I'm trying to show a texture scaled using the Sprite class. 我试图显示使用Sprite类缩放的纹理。 The issue is when I try to run my code.
问题是当我尝试运行代码时。 I can show the textures in Android 4.1, but when I run the same program in another Android, for example 2.2, 2.3.6... the Sprite is not shown.
我可以在Android 4.1中显示纹理,但是当我在另一个Android中运行相同的程序(例如2.2、2.3.6)时,不会显示Sprite。 Here's my code.
这是我的代码。
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;
}
}
}
}
}
Thanks a lot and sorry for my bad english. 非常感谢,抱歉我的英语不好。
It seems like you didn't set the Matrix4 for your batch. 似乎您没有为批次设置Matrix4 。
Use this : 用这个 :
private Matrix4 Projection;
In create() : 在create()中 :
Projection = new Matrix4().setToOrtho2D(0, 0, (float) Gdx.graphics.getWidth(), (float) Gdx.graphics.getHeight());
In render() before batch.begin(); 在batch.begin之前渲染()();
batch.setProjectionMatrix(Projection);
I hope this 'll help you. 希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.