为什么会这样
player.sprite.draw(batch);
不会渲染我的精灵,但是
batch.draw(player.sprite.getTexture(), 0,0 );
呢?
我的完整渲染方法:
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);
}
}
答案 0 :(得分:-1)
我没有使用Sprite的构造函数,并使用Sprite.setTexture设置了Texture,但是这在某种程度上没有正确初始化Sprite。现在使用构造函数我可以渲染它