这是 menuscreen 类,调用时将使用作为参数传递的 spritebatch 绘制菜单屏幕。问题是绘图命令第二次无法执行(即在我们重新启动应用程序之后),而所有其他功能都可以正常工作(如果我们单击放置它的位置,您仍然可以使用我们放置在屏幕上的按钮)
public class MenuScreen extends Screen
{
Texture Background,Playgame,Credits;
Vector2 PlaygamePos,CreditsPos;
Rectangle PlaygameRect,CreditsRect,touchRect;
public MenuScreen()
{
Background = GameEngine.LoadTexture("Menu/bg.png");
GameEngine.BackgroundTexture = Background;
Playgame = GameEngine.LoadTexture("Menu/newgame.png");
Credits = GameEngine.LoadTexture("Menu/credits.png");
PlaygamePos = new Vector2(500,300);
CreditsPos = new Vector2(500,200);
PlaygameRect = new Rectangle(PlaygamePos.x,PlaygamePos.y,Playgame.getWidth(),Playgame.getHeight());
CreditsRect = new Rectangle(CreditsPos.x,CreditsPos.y,Credits.getWidth(),Credits.getHeight());
}
@Override
public void Update(OrthographicCamera camera)
{
if(GameEngine.isBackButton == true)
{
GameEngine.isBackButton = false;
Gdx.app.exit();
}
if(GameEngine.isTouched() == true)
{
Vector3 touchPos = new Vector3();
touchPos = GameEngine.TouchPos(camera);
touchRect = new Rectangle(touchPos.x,touchPos.y,10,10);
if(touchRect.overlaps(PlaygameRect))
{
SelectScreen = ScreenSelect.GamePlay;
}
else if(touchRect.overlaps(CreditsRect))
{
}
}
}
@Override
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.draw(Credits,CreditsPos.x,CreditsPos.y);
spriteBatch.draw(Playgame,PlaygamePos.x,PlaygamePos.y);
}
@Override
public void Resume() {
// TODO Auto-generated method stub
}
@Override
public void Pause() {
// TODO Auto-generated method stub
}
@Override
public void Dispose()
{
}
}
即使我们尝试了处理纹理和 SpriteBatches 也没有奏效!