libgdx의 GestureListener를 사용하여 "TouchUp"을 감지하는 가장 쉽고/쉬운 방법은 무엇입니까? (이전 프로젝트에서는 InputListener를 사용했으나 TouchUp은 있지만 팬 또는 플링은 없었습니다.)gesturelistener를 사용한 libgdx touchup
내가해야 할 일은 손가락이 들리면 내 MovingLeft 또는 MovingRight 불리언 값을 False로 설정하는 것입니다.
package com.moneylife.stashinvaders;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.input.GestureDetector;
import com.badlogic.gdx.math.Vector2;
public class Player {
Vector2 position;
Texture texture;
int speed = 500;
float deltaTime;
int screenWidth, screenHeight;
boolean MovingRight = false, MovingLeft = false;
public Player(int ScreenW, int ScreenH){
Gdx.input.setInputProcessor(new GestureDetector(new MyGestureDetector()));
texture = new Texture("bazookaman.png");
position = new Vector2(Gdx.graphics.getBackBufferWidth()/2 - texture.getWidth()/2, 0);
screenWidth = ScreenW;
screenHeight = ScreenH;
}
public void update(){
deltaTime = Gdx.graphics.getDeltaTime();
if (MovingRight){
position.x += speed * deltaTime;
}
if (MovingLeft){
position.x -= speed * deltaTime;
}
}
public void draw(SpriteBatch spriteBatch){
spriteBatch.draw(texture, position.x, position.y);
}
public class MyGestureDetector implements GestureDetector.GestureListener {
@Override
public boolean touchDown(float x, float y, int pointer, int button) {
if (x > position.x) {
MovingRight = true;
}
if (x < position.x){
MovingLeft = true;
}
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) {
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) {
MovingLeft = false;
MovingRight = false;
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() {
}
}
}
안녕하세요. 나는 이것들에 대해 보았지만, 단순히 터치 업을 얻는 것이 필요한지 확실하지 않았습니다. 당신이 말하고있는 것에서 이것은 최선의 선택입니다. 그래서 지금 이것을 연구 할 것입니다. 다시 한 번 감사드립니다 – Ronny
@ 로니 이러한 제스처가 단일 인터페이스에서 결합되지 않은 이유를 모르지만 실제로는 중요하지 않습니다. 코드에 몇 가지 추가 구현 방법이 있습니다. – Madmenyo
저는 실제로 Gdx.input.isTouched()를 찾고있었습니다. 누군가 IRC에서 친절하게 상기시켜주었습니다. 그런 다음 getX() 및 getY() 메소드를 사용하여 입력을 폴링하면 내 상황이 훨씬 간단 해집니다. 이 프로젝트에서 필요하지 않은 전체 GestureListener 코드를 삭제할 수 있습니다. 이드가 비슷한 두통을 앓고있는 사람이라면 누구나 이것을 추가 할 것을 생각했다. – Ronny