请教各位大佬,我现在需要做一个鼠标滚轮去缩放大地图的功能,地图使用了ScrollView组件,但是不知道怎样去屏蔽组件自带的滚动功能
尝试了以下各种方式,使用鼠标滚轮的时候地图还是能上下滚动
input.off(Input.EventType.MOUSE_WHEEL);
this.scroll.node.off(Input.EventType.MOUSE_WHEEL);
this.scroll.view.node.off(Input.EventType.MOUSE_WHEEL);
this.scroll.content.off(Input.EventType.MOUSE_WHEEL);
this.scroll.node.on(Input.EventType.MOUSE_WHEEL, this.onMapScaleEvent, this);//注册鼠标滚轮事件
然后我在自定义事件里加了各种停止事件穿透的设置,使用鼠标滚轮的时候地图还是一边缩放一边上下滚动。
/**
* 自定义鼠标滚轮事件
*/
onMapScaleEvent(event: EventMouse) {
if (event.getScrollY() > 0) {//向上滚动
this.gamescale += 0.05;
this.setContentScale();
} else if (event.getScrollY() < 0) {//向下滚动
this.gamescale -= 0.05;
this.setContentScale();
}
this.scroll.stopAutoScroll();
this.scroll.cancelInnerEvents = true;
event.setScrollData(0, 0);
event.bubbles = false;
event.propagationStopped = true;
event.propagationImmediateStopped = true;
}
/**
* 设置地图缩放
*/
private setContentScale() {
this.gamescale = Math.min(this.gamescale, GameCommon.ContentScaleRange.max);
this.gamescale = Math.max(this.gamescale, GameCommon.ContentScaleRange.min);
this.scroll.content.setScale(this.gamescale, this.gamescale, 1);
}
我期望的是使用鼠标滚轮的时候只是大地图的缩放,而不希望地图还能上下滚动,请教如何实现,谢谢!!