ClickListener组合拳

ClickListener组合拳

touchDown

touchDown方法在屏幕或者鼠标被按下时触发

public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
		if (pressed) return false;
		if (pointer == 0 && this.button != -1 && button != this.button) return false;
		pressed = true;
		pressedPointer = pointer;
		pressedButton = button;
		touchDownX = x;
		touchDownY = y;
		setVisualPressed(true);
		return true;
	}

需要注意的有两点:

  1. 按下即触发事件。
  2. 该方法有返回值,返回为false时不会继续执行接下来的touchDragged和touchUp监听。

touchDragged

touchDragged方法在鼠标被按住拖曳或者屏幕被滑动的过程中触发。

public void touchDragged (InputEvent event, float x, float y, int pointer) {
		if (pointer != pressedPointer || cancelled) return;
		pressed = isOver(event.getListenerActor(), x, y);
		if (!pressed) {
			// Once outside the tap square, don't use the tap square anymore.
			invalidateTapSquare();
		}
	}

使用时可以和touchDown方法结合使用,如判断滑动距离。

touchUp

touch组合拳的最后一拳,在鼠标抬起或者手指离开屏幕时触发。

public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
		if (pointer == pressedPointer) {
			if (!cancelled) {
				boolean touchUpOver = isOver(event.getListenerActor(), x, y);
				// Ignore touch up if the wrong mouse button.
				if (touchUpOver && pointer == 0 && this.button != -1 && button != this.button) touchUpOver = false;
				if (touchUpOver) {
					long time = TimeUtils.nanoTime();
					if (time - lastTapTime > tapCountInterval) tapCount = 0;
					tapCount++;
					lastTapTime = time;
					clicked(event, x, y);
				}
			}
			pressed = false;
			pressedPointer = -1;
			pressedButton = -1;
			cancelled = false;
		}
	}

结束性操作/变量重置/资源回收等操作可在此处执行。

clicked

组合拳外七伤拳。监听点击事件,但是和touch事件发生冲突,不要同时使用。

public void clicked (InputEvent event, float x, float y) {
	}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值