Why does this
player.sprite.draw(batch);
does not render my sprite, but
batch.draw(player.sprite.getTexture(), 0,0 );
does?
My complete render method:
public void render(float deltaTime) {
if (assets.assetManager.update()) {
loading = false;
player = new Cat(assets.assetManager.get("textures/Cat.png", Texture.class));
player.sprite.setPosition(0,0);
}
else
{
timeLoading += deltaTime;
System.out.println("Progress: " + assets.assetManager.getProgress() * 100);
}
if (!loading)
{
rayHandler.updateAndRender();
Gdx.gl.glClearColor(0.37f, 0.73f, 0.84f, 1f);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
processUserInput();
player.update(deltaTime);
orthogonalTiledMapRenderer.setView(orthographicCamera);
orthogonalTiledMapRenderer.render();
batch.begin();
if (debug)
renderDebugInfo();
player.sprite.draw(batch);
batch.draw(player.sprite.getTexture(), 0,0 );
batch.end();
batch.setProjectionMatrix(orthographicCamera.projection);
rayHandler.setCombinedMatrix(orthographicCamera);
orthographicCamera.update();
world.step(1, 4, 4);
}
}
I had not used the Constructor of Sprite, and set the Texture with Sprite.setTexture, but this somehow did not proper initialize the Sprite. Now with using the Constructor I can render it
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.