我在libgdx做了一个游戏,海龟必须收集海星,但我使用的是演员,所以我不得不使用舞台。在创建了一个舞台之后,我无法在屏幕上绘制精灵,这也会使游戏崩溃
编辑:我忘了把batch.end()放在末尾,但它仍然没有绘制精灵
这是我的密码
@Override
public void render()
{
for (int i=0; i<5; i++)
{
if (Gdx.input.isTouched(i))
{
Vector3 touchPos = new Vector3(Gdx.input.getX(i), Gdx.input.getY(i), 0);
camera.unproject(touchPos);
Rectangle touch = new Rectangle(touchPos.x-16, touchPos.y-16, 32, 32);
if (touch.overlaps(leftButton))
{
moveX-=Gdx.graphics.getDeltaTime()*80;
System.out.println("left touched");
}
if (touch.overlaps(rightButton))
{
moveX+=Gdx.graphics.getDeltaTime()*80;
System.out.println("right touched");
}
if (touch.overlaps(jumpButton))
{
moveY+=Gdx.graphics.getDeltaTime()*80;
System.out.println("up touched");
}
}
}
// check user input
mainStage.act(1/60f);
// check win condition: turtle must be overlapping starfish
if (turtle.overlaps(starfish))
{
starfish.remove();
winMessage.setVisible(true);
}
// clear screen
Gdx.gl.glClearColor(0,0,0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// draw graphics
mainStage.draw();
batch.setProjectionMatrix(camera.combined);
batch.begin();
leftSpriteButton.draw(batch);
rightSpriteButton.draw(batch);
jumpSpriteButton.draw(batch);
}
暂无答案!
目前还没有任何答案,快来回答吧!