触地得分和触地得分事件的工作原理-LibGdx

How touchdown and touchup events work-LibGdx

我有两个事件要在同一个 object.One 触摸和另一个 releasing/removing 触摸上执行。 我希望我可以使用 Inputprocessor 处理接触和接触事件。

我试过的东西。

if (MyInputProcessor.isTouchDown) {

        stickSprite.setSize(stickSprite.getWidth(), stickSprite.getHeight()    + 500.0f);
        } 

       if (MyInputProcessor.isTouchUp)
        {
             if(anglevalue>=0)
                {
                    anglevalue++;
                stickSprite.setRotation(70f);

                }
        }

这里没有执行 touch up 的 if 子句。

这些活动实际上是如何运作的?

我怎样才能有效地使用这些事件来满足我的要求?

看起来,您想要在用户触摸屏幕时增加图像的高度尺寸,并增加直到他将手指从屏幕上移开,然后将该图像旋转 90 度。

这个我试过了,希望能给你一些参考

public class TestGame extends Game implements InputProcessor{

Texture pixelTex;

SpriteBatch spriteBatch;
Sprite sprite;
float w,h;

TouchStatus touchStatus=TouchStatus.NONE;

enum TouchStatus {
    TOUCH_DOWN,TOUCH_UP,NONE
}

@Override
public void create() {

    w=Gdx.graphics.getWidth();
    h=Gdx.graphics.getHeight();
    Gdx.input.setInputProcessor(this);

    spriteBatch=new SpriteBatch();
    pixelTex= getPixmapTexture(Color.WHITE);

    sprite=new Sprite(pixelTex);
    sprite.setColor(Color.YELLOW);
    sprite.setSize(10,10);
    sprite.setPosition(200,200);
}

@Override
public void render() {
    super.render();

    Gdx.gl.glClearColor(1,1,1,1);
    gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    spriteBatch.begin();
    sprite.draw(spriteBatch);
    spriteBatch.end();

    if(touchStatus==TouchStatus.TOUCH_DOWN){

        if(sprite.getY()+sprite.getHeight()<h){
            float currentHeight=sprite.getHeight();
            currentHeight++;
            sprite.setSize(sprite.getWidth(),currentHeight);
        }
    }
    if(touchStatus==TouchStatus.TOUCH_UP){
        float currentRotation=sprite.getRotation();
        currentRotation--;
        sprite.setRotation(currentRotation);
        if(currentRotation<=-90)
            touchStatus=TouchStatus.NONE;
    }
}

@Override
public void resize(int width, int height) {
    super.resize(width, height);
}

@Override
public void dispose() {
    super.dispose();
    pixelTex.dispose();
    spriteBatch.dispose();
}

@Override
public boolean keyDown(int keycode) {

    return false;
}

@Override
public boolean keyUp(int keycode) {
    return false;
}

@Override
public boolean keyTyped(char character) {
    return false;
}

@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {

    if(touchStatus==TouchStatus.NONE)
    touchStatus=TouchStatus.TOUCH_DOWN;
    return false;
}

@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
    if(touchStatus==TouchStatus.TOUCH_DOWN)
    touchStatus=TouchStatus.TOUCH_UP;
    return false;
}

@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
    return false;
}

@Override
public boolean mouseMoved(int screenX, int screenY) {
    return false;
}

@Override
public boolean scrolled(int amount) {
    return false;
  }

public static Texture getPixmapTexture(Color color){
        return new Texture(getPixmapRectangle(1, 1, color));
}

public static Pixmap getPixmapRectangle(int width, int height, Color color){
        Pixmap pixmap=new Pixmap(width, height, Pixmap.Format.RGBA8888);
        pixmap.setColor(color);
        pixmap.fillRectangle(0,0, pixmap.getWidth(), pixmap.getHeight());

        return pixmap;
   }
 }