gpt4 book ai didi

java - Shooter 类型的 getMouseX() 方法未定义

转载 作者:太空宇宙 更新时间:2023-11-04 10:57:11 25 4
gpt4 key购买 nike

我一直在使用 HSA_UFA 控制台,它不是很常见,但这是我在学校学到的东西。我正在使用 Java,它给了我错误:“The method getMouseX() is undefined for the type Shooter”

public class Shooter {

static Console c = new Console(1000, 1000, 20, "S H O O T E R");

public static void main(String args[]) throws InterruptedException {

int playerSpeed = 2;
int playerX = 0;
int playerY = 0;

while(true) {

//Drawing Frame
synchronized (c) {
c.clear();
c.fillRect(playerX, playerY, 15, 15);
}

//Schleeeeep
Thread.sleep(10);

//Player Controls
if (c.isKeyDown('W')) {

playerY -= playerSpeed;

}

if (c.isKeyDown('S')) {

playerY += playerSpeed;
}

if (c.isKeyDown('A')) {

playerX -= playerSpeed;

}

if (c.isKeyDown('D')) {

playerX += playerSpeed;

}

if (c.getMouseButton(2)) {

playerX = getMouseX();
playerY = getMouseY();

}

}

}

}

最佳答案

您应该使用控制台变量来访问 getMouseX(),因为您正在捕获控制台窗口上的鼠标位置。在调用此方法之前,可以调用 enableMouse()enableMouseMotion() 以确保安全。

public static void main(String arSgs[]) throws InterruptedException {

int playerSpeed = 2;
int playerX = 0;
int playerY = 0;

//enabling mouse capturing
c.enableMouse();
c.enableMouseMotion();

while(true) {

/*
* your code
*/

if (c.getMouseButton(2)) {

playerX = c.getMouseX();
playerY = c.getMouseY();

}
}

关于java - Shooter 类型的 getMouseX() 方法未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47243693/

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