gpt4 book ai didi

java - 如何在 Piccolo 2D 中反转鼠标滚轮缩放处理?

转载 作者:行者123 更新时间:2023-12-01 12:57:55 30 4
gpt4 key购买 nike

在大多数应用中,向下旋转滚轮会减小缩放对象的尺寸,而向上旋转滚轮会增大尺寸。

在 piccolo2d 中,默认行为是相反的:

private static void showWorldNode() {
new PFrame() {

@Override
public void initialize() {

getCanvas().getLayer().addChild(worldNode);

PMouseWheelZoomEventHandler mouseWheelZoomEventHandler = new PMouseWheelZoomEventHandler();
mouseWheelZoomEventHandler.zoomAboutMouse();
getCanvas().addInputEventListener(mouseWheelZoomEventHandler);
}

};
}

如何恢复默认?

最佳答案

您可以提供负比例因子来反转行为,例如:

mouseWheelZoomEventHandler.setScaleFactor(-0.1d);

PMouseWheelZoomEventHandler 根据比例因子和 MouseWheelEvent.getWheelRotation() 的值计算缩放值返回:

negative values if the mouse wheel was rotated up/away from the user, and positive values if the mouse wheel was rotated down/ towards the user

这里是来自PMouseWheelZoomEventHandler的相关代码

double scale = 1.0d + event.getWheelRotation() * scaleFactor;

关于java - 如何在 Piccolo 2D 中反转鼠标滚轮缩放处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23742786/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com