Comments (12)
@minggo 一个能完整重现此 bug 的代码.
import * as cc from 'cc';
const { ccclass, property } = cc._decorator;
@ccclass()
export class TestInputBugScene extends cc.Component {
// 一个供测试的节点, 实际大小铺满了整个屏幕, 所以不存在没有点击到的情况
@property(cc.Node)
testNode: cc.Node = null;
touchId: number = null;
protected onLoad (): void {
cc.macro.ENABLE_MULTI_TOUCH = false;
this.testNode.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this, false);
this.testNode.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this, false);
}
onTouchStart (event: cc.EventTouch): void {
if (event.getAllTouches().length > 1) {
return;
}
this.touchId = event.getID();
console.log('onTouchStart', event.getType(), event.getID(), event.getAllTouches().length);
}
onTouchEnd (event: cc.EventTouch): void {
if (event.getAllTouches().length > 0) {
return;
}
if (this.touchId !== event.getID()) {
return;
}
// ENABLE_MULTI_TOUCH = false 时, 微信小游戏下, 不会执行到此处, 这行不打印
// 如果 ENABLE_MULTI_TOUCH = true 的话 则一切正常.
console.log('onTouchEnd', event.getType(), event.getID(), event.getAllTouches().length);
this.touchId = null;
}
}
from cocos-engine.
issue 最好包括:
- 重现步骤
- 错误的表现
- 能有 demo 最好
from cocos-engine.
@minggo , ENABLE_MULTI_TOUCH = true 时, 如果此时有一个手指放在屏幕上(这个是合理的) , _checkTouchMapSizeMoreThanMax() 仍然会返回 true . 这是不对的, 1 并不 more than 1 , more than 的意思应该是大于 . 然后进而后续引起一系列的错误.
在我的项目里, 具体情况是 touch_end 相关的代码无法被正确执行.
from cocos-engine.
补充下, 是 小程序里 , 浏览器里没有问题.
from cocos-engine.
在我的项目里, 具体情况是 touch_end 相关的代码无法被正确执行.
任何的 touch_end 代码无法被执行吗?有什么特殊要求吗?
from cocos-engine.
在我的项目里, 具体情况是 touch_end 相关的代码无法被正确执行.
任何的 touch_end 代码无法被执行吗?有什么特殊要求吗?
只是判断了 event.getID() 抬起的手指的id 是否等于当初 按下的.
你可以无视 我上面 关于 _checkTouchMapSizeMoreThanMax 的分析. 因为我犯了个错误, 用web的代码 去分析 微信小游戏....
ENABLE_MULTI_TOUCH = true 时, ok, ENABLE_MULTI_TOUCH = false 时 , 不ok.
全程我都只是拿一根手指测试的. 没有多点触控.
from cocos-engine.
所以我可以这样总结:
- ENABLE_MUTLTI_TOUCH = false 时
- 在小游戏里(微信平台还是别的平台?),只使用一个手指测试(按下、弹起?还是按下、移动、再弹起?弹起位置是否超出控件范围?)
- 导致游戏逻辑的 TOUCH_END 事件没法被调用到(事件是注册在某个 UI 控件?还是别的什么控件?)
虽然我们上面有些交流,但还是有些信息缺失。有些问题可能就是在特殊情况才出现的,因此我才建议最好给 demo,否则的话就得把问题描述得清楚些。这样我们修复也才好验证。甚至我们的测试组就可以根据 demo 直接验收。
from cocos-engine.
收到,谢谢。
from cocos-engine.
@finscn 没太理解这个有什么问题?
_checkTouchMapSizeMoreThanMax是在createTouch里的,creatorTouch是touchid没有遍历到才调用的。而_checkTouchMapSizeMoreThanMax里面的判断是正确的,因为_checkTouchMapSizeMoreThanMax判断为false(正常的情况下也是false)之后会push,也就是说刚开始是0,后面push之后是1。
// ENABLE_MULTI_TOUCH = true 时, maxSize = 1,
这个注释也有问题,应该是ENABLE_MULTI_TOUCH = false时,才为1.
另外,你说的_checkTouchMapSizeMoreThanMax的问题与这个现象是没有关系的,无论改了还是没改,走的逻辑是一样的。
出现ENABLE_MULTI_TOUCH的true或者false造成差异的问题是:
因为touch_end事件会移除掉touchid,而ENABLE_MULTI_TOUCH为true使用的是touchManager.getAllTouches()(touch事件被移除了,所以touchend消息监听里没有打印)。
ENABLE_MULTI_TOUCH为false使用的是handleTouches(这里肯定是有一个touch事件)
逻辑上是正确的。
另外,我想问问
···
if (event.getAllTouches().length > 0) {
return;
}
···
这里为啥要这样判断?有touch的要全部reture?
from cocos-engine.
@qiuguohua , 是的 . 我后来也发现 不是 _checkTouchMapSizeMoreThanMax的锅了.
.length > 0 的目的是希望 手指全部抬起后 才处理 touchend事件里的逻辑, 有手指在屏幕 不处理.
这个bug应该和这个 >0 的判断无关. 因为 ENABLE_MULTI_TOUCH = true 时, 一切正常.
from cocos-engine.
@finscn 你看截图的代码哈,如果ENABLE_MULTI_TOUCH = false的话,用的是handleTouches是不会移除的,始终会push进去。所以理论上代码逻辑是这样。功能上应不应该移除,我得问问产品
from cocos-engine.
@qiuguohua 但是不管怎样, 在我始终都只有一个手指 触碰屏幕时, ENABLE_MULTI_TOUCH = false 和 ENABLE_MULTI_TOUCH = true 的结果和行为应该是一样的. 我的这个观点麻烦你也和你们产品反馈下.
from cocos-engine.
Related Issues (20)
- 移动正交相机,相机预览画面残留。
- [spine动画API] 缺少 `trackEntry.getAnimationLast/setAnimationLast()` 方法的声明
- Layout组件能否改成同帧刷新
- 统一bundle包中config.json文件名
- 微信小游戏电脑端插屏BUG: 缩放不对. HOT 1
- Label组件的阴影效果在 微信小游戏iPad 版本上无效 HOT 1
- 加载场景有概率报错
- [native] memory leak while changing label ( CacheMode: NONE) text. HOT 1
- angle cannot get correctly,
- Native build don't have the ability to make changes and collaborate with multiple people.
- [bug] Tween property type was changed to plain object
- 功能裁剪能否支持不同平台做不同设置
- The problem of not being able to effectively recognize the textureGrab function during the shader compilation with glslang.js when running WebGPU HOT 2
- [3.8.3] The image resources in tga format in the project cannot be exported as astc during the build process
- [3.8.x] There is a need to support the output of js sourceMap files when building projects for native platforms
- 自定义渲染管线中DevicePass里framebuffer中的texture可能失效
- 3.8.3的dragonBones引入后打印出来是个undefined
- In CocosEditor, FBX Animation will be from slow to quick
- [3.8.3] When js encounters an error code, it is unable to correctly output the code call stack information mapped by sourceMap HOT 2
- In CocosEditor and On web browser, FBX Animation Bake Rate changed, cannot take effect
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cocos-engine.