对不起我的问题,但我被困了。我是用lib gdx开发游戏的新手,并且不要严格评判我。 我有我的游戏活动:
public class MyGame extends Game {
MenuScreen menu;
SplashScreen splash;
DefendScreen def;
@Override
public void create() {
// Gdx.app.log("LogGame", "MyGame create");
menu = new MenuScreen(this);
splash = new SplashScreen(this);
def = new DefendScreen(this);
setScreen(splash);
}
@Override
public void resize(int width, int height) {
}
@Override
public void render() {
super.render();
}
@Override
public void pause() {
super.pause();
}
@Override
public void resume() {
super.resume();
}
@Override
public void dispose() {
}
}
我有两个屏幕:
public class MenuScreen implements Screen, InputProcessor {
public MenuScreen(final MyGame gam) {
game = gam;
cam = new OrthographicCamera();
cam.setToOrtho(false, 800, 480);
w = Gdx.graphics.getWidth();
h = Gdx.graphics.getHeight();
defScreen = new DefendScreen(game);
spriteBatch = new SpriteBatch();
stage = new Stage();
}
@Override
public void dispose() {
Gdx.app.log("LogGame", "splashs dispose");
Gdx.input.setInputProcessor(null);
try {
spriteBatch.dispose();
stage.dispose();
font12.dispose();
} catch (Exception e) {
}
}
@Override
public void hide() {
// TODO Auto-generated method stub
}
@Override
public void pause() {
}
@Override
public void render(float arg0) {
SetCamera(CAMERA_WIDTH / 2, CAMERA_HEIGHT / 2f);
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(); // update all actors
stage.draw();
}
@Override
public void resize(int arg0, int arg1) {
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
@Override
public void show() {
stage.addActor(new WorldMenu(new Texture(Gdx.files
.internal("images/bg/pause_back.png"))));
Gdx.input.setInputProcessor(stage);
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(
Gdx.files.internal("font/trebuchet_ms.ttf"));
FreeTypeFontParameter parameter = new FreeTypeFontParameter();
parameter.size = 25;
font12 = generator.generateFont(parameter);
generator.dispose();
DrawLeftMeu();
DrawRightMeu();
DrawSetingsMenu();
}}
我有暂停按钮的游戏画面:
public class DefendScreen implements Screen, InputProcessor {
public DefendScreen(final MyGame gam) {
game = gam;
cam = new OrthographicCamera();
cam.setToOrtho(false, 800, 480);
startTime = TimeUtils.millis();
spriteBatch = new SpriteBatch();
stage = new Stage();
w = Gdx.graphics.getWidth();
h = Gdx.graphics.getHeight();
}
@Override
public void dispose() {
Gdx.app.log("LogGame", "defend dispose");
try {
combo0.dispose();
combo1.dispose();
combo2.dispose();
good0.dispose();
good1.dispose();
bad0.dispose();
bad1.dispose();
bad2.dispose();
bad3.dispose();
bad4.dispose();
music.dispose();
music.stop();
spriteBatch.dispose();
font.dispose();
pbar.dispose();
scores.dispose();
} catch (Exception e) {
}
}
@Override
public void hide() {
}
@Override
public void pause() {
// this.state = State.PAUSE;
}
@Override
public void render(float delta) {
SetCamera(CAMERA_WIDTH / 2, CAMERA_HEIGHT / 2f);
switch (state) {
case RUN:
RunGame();
break;
case PAUSE:
// do stuff here
break;
case RESUME:
break;
default:
break;
}
}
@Override
public void resize(int arg0, int arg1) {
}
@Override
public void resume() {
this.state = State.RESUME;
}
@Override
public void show() {
regions = new ArrayList<Integer>();
addRegions();
initSounds();
speedgame = speedgameEasy;
stage.addActor(worldActor);
stage.addActor(pauseActor);
startTime = TimeUtils.millis();
stage.addListener(clickList);
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(
Gdx.files.internal("font/trebuchet_ms.ttf"));
FreeTypeFontParameter parameter = new FreeTypeFontParameter();
parameter.size = 25;
font = generator.generateFont(parameter);
generator.dispose();
pbar = new Texture(Gdx.files.internal("images/bg/line_indicator.png"));
scores = new Texture(
Gdx.files.internal("images/game_images/scorebox.png"));
Gdx.input.setInputProcessor(stage);
Gdx.input.setCatchBackKey(true);
}}
我的主要问题!!! - &GT;我必须做什么,暂停行动我可以冻结游戏动作和呼叫菜单屏幕(哇有按钮恢复)? - &GT;什么我在恢复onclick做什么做显示游戏动作简历? 在stackoverflow其他论坛我找到一些关于我的问题的解释,这意味着在简历中实现一些选择游戏状态的切换案例,但我不明白它在我的代码中是如何实现的。 谢谢大家。
答案 0 :(得分:-3)
在你的游戏画面中你应该有一个按钮(一个演员添加到舞台上),它实现了一个ClickListener,它根据游戏的当前状态调用pause()
或resume()
。
看起来应该是这样的:
pauseButton.addListener(new ClickListener() {
public void clicked(InputEvent evt, float x, float y) {
if (!paused) Gdx.app.getApplicationListener().pause();
else Gdx.app.getApplicationListener().resume();
}
});
其中paused
是游戏屏幕类中的布尔变量。
在我看来,这是最简单的方法。