我正在开发一款安卓游戏。整个游戏都在“游戏”类中。问题是当我想要重新开始选项时,我不知道如何从“Gameplay”类中删除“mg”对象并制作一个新对象。这是我的代码:
package com.PJA.game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class GameScreen extends BaseScreen {
static short state=1;
Gameplay mg;
Menu mm;
LostScreen ls;
public GameScreen(Gra game) {
super(game);
mm=new Menu();
mg=new Gameplay();
ls=new LostScreen();
}
public void update() {
if(state==1) mm.live();
if(state==2) mg.live();
if(state==3) ls.live();
Gdx.app.log("CurrentState: ", Integer.toString(state));
}
public void drau(SpriteBatch sb) {
if(state==1) mm.show(sb);
if(state==2) mg.show(sb);
if(state==3) ls.show(sb);
}
}