gpt4 book ai didi

java - LibGDX:在单独的类中创建 GestureListener

转载 作者:行者123 更新时间:2023-11-30 00:47:23 24 4
gpt4 key购买 nike

<分区>

我目前有一个类可以处理我想要的所有手势,它看起来像这样:

public class InputHandler  implements GestureDetector.GestureListener{

private Player myPlayer;

public InputHandler(Player player){
myPlayer = player;
}

@Override
public boolean touchDown(float x, float y, int pointer, int button) {
return false;
}

@Override
public boolean tap(float x, float y, int count, int button) {
return false;
}

@Override
public boolean longPress(float x, float y) {
return false;
}

@Override
public boolean fling(float velocityX, float velocityY, int button) {
if(velocityY > 0){
myPlayer.onSwipeUp();
}
return false;
}

@Override
public boolean pan(float x, float y, float deltaX, float deltaY) {
return false;
}

@Override
public boolean panStop(float x, float y, int pointer, int button) {
return false;
}

@Override
public boolean zoom(float initialDistance, float distance) {
return false;
}

@Override
public boolean pinch(Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
return false;
}

@Override
public void pinchStop() {

}
}

如您所见,我使用的唯一方法是“fling”方法,但我想在我的“MainScreen”类中创建手势监听器,因为它包含对“myPlayer”的引用,我想将其传递进入这个类,但我不确定如何创建监听器。到目前为止,我的构造函数中有这个:

public class GameScreen implements Screen {

private GameWorld world;
private GameRenderer renderer;
GestureDetector gd;


public GameScreen(){
float screenWidth = Gdx.graphics.getHeight();
float screenHeight = Gdx.graphics.getWidth();
float gameWidth = 816;
float gameHeight = screenHeight/(screenWidth/gameWidth);

int midpointY = (int)(gameHeight/2);

world = new GameWorld(midpointY);
renderer = new GameRenderer(world);

gd = new GestureDetector(new myGestureListener(world.getPlayer())); //Error here, 'myGestureListener' cannot be resolved
Gdx.input.setInputProcessor(gd);



}

我知道“myGestureListener”从未创建过,因此无法解决,但我对如何修复此错误同时确保正确传递引用感到困惑。如果我需要初始化一个 GestureListener,我该怎么做?

如果这个问题没有意义或没有解决方案,我提前道歉,我对使用 libGDX 框架进行编码仍然是新手。

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