gpt4 book ai didi

java - 程序未检测到鼠标点击

转载 作者:行者123 更新时间:2023-12-02 05:35:59 30 4
gpt4 key购买 nike

我正在编写我的第一个游戏,但无法让我的菜单屏幕正常工作。下面是我的菜单的代码。我一直在尝试测试退出按钮,但是无论我点击哪里,程序都不会退出。我还尝试将 System.out.println(e.getX()+", "+e.getY()); 添加到我的 mousePressed() 方法中没有运气;它不会打印任何东西。我完全迷路了,需要任何帮助。抱歉,如果这是一个愚蠢的问题,我对此完全陌生!谢谢!

public class MenuScreen implements Screen {
MyGame game;
OrthographicCamera camera;
SpriteBatch batch;

public MenuScreen(MyGame game) {
this.game = game;

camera = new OrthographicCamera();
camera.setToOrtho(false, 1080, 1920);

batch = new SpriteBatch();
}

public class MouseInput implements MouseListener {

@Override
public void mouseClicked(MouseEvent arg0) {}

@Override
public void mouseEntered(MouseEvent arg0) {}

@Override
public void mouseExited(MouseEvent arg0) {}

@Override
public void mousePressed(MouseEvent e) {

int mx = e.getX();
int my = e.getY();

/**
batch.draw(Assets.sprite_startbutton, 165, 955);
batch.draw(Assets.sprite_tutorialbutton, 325, 790);
batch.draw(Assets.sprite_exitbutton, 365, 700);
batch.end();
*/
//exit button
if (mx >= 365 && mx <= 600) {
if (my >= 700 && my <= 775) {
//Pressed exit button
System.exit(1);
}
}
}

@Override
public void mouseReleased(MouseEvent arg0) {}
}

public void render(float delta) {
Gdx.gl.glClearColor(1F, 1F, 1F, 1F);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

camera.update();

batch.setProjectionMatrix(camera.combined);

batch.begin();
batch.draw(Assets.texture_background, 0, 0);
batch.draw(Assets.sprite_cat, 500, 1350, 750, 263);
//(500, 1350, 750, 263)[Cat on shelf]
//(95, 1600, 900, 316)[Cat starting position]
batch.draw(Assets.sprite_title, 50, 1600);
batch.draw(Assets.sprite_startbutton, 165, 955);
batch.draw(Assets.sprite_tutorialbutton, 325, 790);
batch.draw(Assets.sprite_exitbutton, 365, 700);
batch.end();
}

最佳答案

看起来您正在 libgdx 应用程序中使用 MouseListener,它适用于 AWT,但它在您的设置中不起作用。使用 Gdx.input 轮询输入(或 InputListener)。

您还可以看看这个教程:http://www.gamefromscratch.com/post/2013/10/15/LibGDX-Tutorial-4-Handling-the-mouse-and-keyboard.aspx

关于java - 程序未检测到鼠标点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24967153/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com