鼠标滚轮事件问题

请教各位大佬,我现在需要做一个鼠标滚轮去缩放大地图的功能,地图使用了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);
}

我期望的是使用鼠标滚轮的时候只是大地图的缩放,而不希望地图还能上下滚动,请教如何实现,谢谢!!

使用的引擎版本是3.4.2,测试平台是chrome浏览器

可不可以换个思路 放大的过程中
this.node.getComponent(ScrollView).enabled = false
放大结束
this.node.getComponent(ScrollView).enabled = true

感谢回复,尝试了一下这个方式还是边缩放边滚动

this.scroll.enabled=false;
//缩放逻辑
setTimeout(()=>{this.scroll.enabled=true}, 0.1);

我设置一下间隔,不在这一帧恢复组件是可以起作用了。不过这毕竟是取巧了,没有从核心上解决问题,还是希望官方能给出修改滚轮滚动事件的接口

你自己重写一个继承scrollview的类,然后重写_onMouseWheel这个方法,这个方法是个空函数,应该行的吧

1赞

直接移除掉鼠标滚轮的监听,用targetOff

完美解决,感谢!!!