カスタムスプライトをレンダリングしたいと思います。 1 world unit = 1 card
幅、like is done here
しかし、スプライトはレンダリングされません。これは前に働いていましたが、私はなぜそれが今ではないのだろうと思います。空白の画面をレンダリングするだけです。ここ libgdxスプライトが突然レンダリングされず、カスタム世界単位で表示されます
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
public class MyGame extends ApplicationAdapter {
SpriteBatch batch;
Sprite sprite;
TextureAtlas atlas;
OrthographicCamera cam;
float CARDWITH=1f;//chosen as our world unit
float CARDHEIGHT=108f/76f;
float MINIMUM_VIEWPORT_SIZE=10f;//our viewport is 10 card widths wide
@Override
public void create() {
batch = new SpriteBatch();
atlas=new TextureAtlas(Gdx.files.internal("cardspack.atlas"));
sprite=atlas.createSprite("c2");
sprite.setSize(CARDWITH,CARDHEIGHT);//make 1 unit of our world equal to 1 card width.
cam=new OrthographicCamera();
}
@Override
public void resize(int width, int height) {
if(width>height){
cam.viewportHeight=MINIMUM_VIEWPORT_SIZE;
cam.viewportWidth=cam.viewportHeight*(float)width/(float)height;
}
else {
cam.viewportWidth=MINIMUM_VIEWPORT_SIZE;
cam.viewportHeight=cam.viewportWidth*(float)height/(float)width;
}
cam.update();
}
@Override
public void render() {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
sprite.draw(batch);
batch.end();
}
@Override
public void dispose() {
batch.dispose();
}
}
Here is the texture atlas cardspack.atlas
です link to the image of cardspackあなたのカードが(0、0 COORDSで)表示されたが、それは小さすぎるされ