Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LButton有bug #25

Open
androids7 opened this issue Jun 2, 2019 · 2 comments
Open

LButton有bug #25

androids7 opened this issue Jun 2, 2019 · 2 comments

Comments

@androids7
Copy link

这段代码里,我给这个按钮添加了两张图片,显示是正常的。但是按下后就不正常了,是不是case 2里的代码有问题,这是源码
public void setImages(LTexture... images) {
LTexture[] buttons = new LTexture[4];
if (images != null) {
int size = images.length;
this.type = size;
switch (size) {
case 1:
buttons[0] = images[0];
buttons[1] = images[0];
buttons[2] = images[0];
buttons[3] = images[0];
break;
case 2:
buttons[0] = images[0];
buttons[1] = images[1];
buttons[2] = images[0];
buttons[3] = images[0];
break;
case 3:
buttons[0] = images[0];
buttons[1] = images[1];
buttons[2] = images[2];
buttons[3] = images[0];
break;
case 4:
buttons = images;
break;
default:
exception = true;
break;
}
}
if (!exception) {
this.setImageUI(buttons, true);
}

}
@androids7
Copy link
Author

快点修复bug吧,我要哭了,游戏主界面因为引擎bug没得做出来

@cping
Copy link
Owner

cping commented Jun 2, 2019

您好,这确实是个bug,但和LButton本身无关,这是一个Desktop的处理方式问题, 导致LButton处理悬停图时处理错误(LButton默认的最多四张图是,默认,悬停(鼠标滑过),按下,禁用)。错误原因在于processTouchExited函数在手机环境中没有有效执行。原始方法中,在组件管理类Desktop的processTouchMotionEvent函数中,有一处组件查找方法

LComponent comp = this.findComponent(touchX, touchY);

他会对比鼠标位置下是否有组件,如果没有或者组件改变再执行已有组件的processTouchExited函数,在桌面上,根据鼠标滑动位置处理所获得的数据肯定是正确的,因为屏幕中鼠标轨迹就算不点击屏幕,也会随着移动变化,鼠标离开组件或屏幕processTouchExited也就执行了。

因为这个引擎最早版本是仅有桌面环境的,所以当初的设计没有问题。

但是,运行在手机环境,touch只有按下和拖拽还有放开时会获得touch位置,所以会造成这个方法在touch有操作前不能被执行,而且执行后不点击屏幕选中的组件也不会改变,所以processTouchExited触发时机会变得很奇怪。

现在我把这部分代码改成了

		// 获得当前窗体下鼠标坐标
		LComponent comp = null;
		if (SysTouch.getButton() != -1) {
			comp = this.findComponent(touchX, touchY);
		}

也就是一旦Touch无状态,则当前选中组件不查找,直接清空重新计算,这样touch无状态(没有任何操作)时processTouchExited就会生效。

不过悬停状态图也会执行不到,因为comp=null也就是没有组件被选中,也就没有悬停事件了,自然不会换图。这会需要细分一下拖拽和点击才能处理好,暂时先这样(毕竟touch的drag和down有时差不多,区分不好会产生类似闪烁的感觉,所以暂时先不处理了。其实不处理从逻辑上讲也是没错的,毕竟触屏本来也没有鼠标悬停事件……)。

bug已经修复,目前您可以java文件夹下的jar获得,等0.5正式发布后我会同步到maven。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants