【bug】使用pixi做虚拟摇杆时候发现的bug-不同的touch事件最后都可以出发touchend,即使没有touchstart先

本文深入分析了Pixi.js交互管理器在处理多点触摸输入时存在的问题,并提供了相应的解决方案。通过引入事件管理器的对象形式存储触摸状态,以及在触摸事件处理器中进行事件数据的更新,实现对多个触摸点的正确响应。讨论了自定义事件管理器的必要性和多点触摸功能的实现细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

资料

[这一篇有价值:Multitouch (Joystick + Button) not working, only repsonding to latest touch #1979]
(https://github.com/pixijs/pixi.js/issues/1979)

UncleAcid commented on 16 Jul 2015


v3's interaction manager is not allowing me to have a joystick with a button in my game (run and jump). I touch the joystick and it's fine, as soon as I touch anywhere else as well the joystick starts responding to where the latest moved touch is.

Am I just missing something or is this a bug in the interaction manager ?

In my touch start I'm setting this.data = event.data and in my touch moved I'm using this.data.getLocalPosition ...

I am aware of #1917, but I can't figure out how to implement it (I've tried so many ways and nothing works), and I'm not even sure that will solve my problem because there's no demo or anything.
englercj commented on 16 Jul 2015


or is this a bug in the interaction manager ?
That, multitouch support doesn't work in the current Interaction manager.
UncleAcid commented on 16 Jul 2015


Ah, lame. I'm just going to try @weepy's hack from #1917 once he posts it and see if that works for now.

You may want to remove the comment "This manager also supports multitouch." from the interaction manager's constructor for now (until it actually does support multitouch) as it's misleading.
GoodBoyDigital commented 25 days ago

closing this as multitouch support is working in dev branch. (using data.identifier) thanks!

Multitouch behaviour #2338

好了,摘要如下:

stdiopt commented 22 days ago

Hi I was trying to create a pinch to scale feature, and come to realize that Event is being fired for every finger independently causing some excessive calls tho performance issues on mobile phones.

is there any plans in this matter? I've seen in code the InteractionManager "//TODO POOL"

fs-manabu-iwata commented 20 days ago

Hi. This library works fine for me.
https://github.com/dekimasoon/pixi-simple-gesture
stdiopt commented 20 days ago


Hi, Thanks for the suggestion

It seems that, that lib uses pixijs on('touchmove') which is the same called once per finger in a pinch its called twice, I ended up implementing gesture myself using default touchmove event from html5 and some pixijs internals to map touch to local, this way is called less frequent (pool) even if two fingers moved
@stdiopt
stdiopt commented 20 days ago
Sample tests:

https://jsfiddle.net/jorg6zt9/1/
https://www.youtube.com/watch?v=cqemvQwzgls
stdiopt commented 20 days ago


Sample tests:

https://jsfiddle.net/jorg6zt9/1/
https://www.youtube.com/watch?v=cqemvQwzgls

另一篇资料:
Multitouch Interaction Manager #1917


weepy commented on 24 Jun 2015


I was under the impression that PIXI v3 was "multitouch ready". However looking at the InteractionManager, it seems that there's a single .eventData property that holds the state of the various touches. Its properties get overwritten when various touches get updated - meaning it's impossible to reason about the state of the touches.

It seems to me that to fix this we should make eventData an object using the key of each touch ? 
Does this seem like a sensible approach ? 
J
RoryPicko commented on 24 Jun 2015


@weepy I have managed a multitouch PinchGesture using e.data.originalEvent.touches within one touch 'touchstart' event on a Container, is this what you mean?
weepy commented on 24 Jun 2015


I mean that this.eventData is essentially the last touch event, but this isn't very useful if you want to process another touch that was previous to this.

I'm trying out a hack that swaps this.eventData to the current touch in each of the handlers like so :

this.eventData = this.eventDataObject[touchData.identifier] = this.eventDataObject[touchData.identifier] || this.createNewEventData()
UncleAcid commented on 16 Jul 2015


I'm having an issue (#1979) that sounds like your hack would work but I can't figure out how to implement it, or if I did implement it properly it didn't work. Because I'm not sure if this will solve my issue, I'm not sure if I implemented it correctly.

Do you have a jsfiddle or something with your fix in place ?
weepy commented on 16 Jul 2015


Yes my fix has been working for me. I can upload soon...
weepy commented on 16 Jul 2015
so I replaced :

    this.eventData = {
        stopped: false,
        target: null,
        type: null,
        data: this.mouse,
        stopPropagation:function(){
            this.stopped = true;
        }
    };

with

    this.eventDataObject = {}
    this.createNewEventData = function() {
        return {
            stopped: false,
            target: null,
            type: null,
            data: this.mouse,
            stopPropagation:function(){
                this.stopped = true;
            }
        };
    }
    this.eventData = this.createNewEventData()
and added

this.eventData = this.eventDataObject[touchData.identifier] = this.eventDataObject[touchData.identifier] || this.createNewEventData()
after each (3 of):

 touchData.originalEvent = event;
here's the latest version of pixi + my changes

https://gist.github.com/weepy/73354fb4e0022ce12939
UncleAcid commented on 16 Jul 2015


Thanks for posting, that's exactly what I had done when trying to implement this however there is no change to the behavior for me.

I start dragging the joystick and all is well and then as soon as I touch anything else the joystick is now responding to that touch, and then whatever touch is the most recently updated ... I don't know what I'm missing here.
SirKnightDragoon commented on 6 Aug 2015


Actualy, you can do multitouch with Pixi v3, but you need to build your own EventManager to control the touches id in memory, the order to know the first, second touch etc.

My events tested: start, move, end, endout, endorout, tap, doubletap, pinchstart, pinchmove, pinchend, hold, holdlong.

I'm working on a editor, with move, zoom, multitouch pinch like googlemap, so yes that's work !

You need:

e.data.originalEvent.timeStamp
e.data.originalEvent.touches
e.data.originalEvent.changedTouches
changedTouches[i].identifier (i == index)
changedTouches[i].clientX ... Y

With all these data, you should do it easily!
Friksel commented 3 days ago


Hum... I was hoping multitouch was working out of the box too, like the repository of pixi v3 there says.
There is an example on http://www.goodboydigital.com/pixijs/examples/8/ where it does work, but that's still build on pixi version 1 wich isn't compatible with v3. 
With the growing number of mobile/touch devices and the growing use of multitouch as intuitive interaction an easy way of handling multitouch would be nice inside the standard pixi lib in my opinion.

Any chance this will be implemented any time soon? Or will this work in v4?

第三篇资料
Multitouch: objects receive wrong touchend event #2309

alclub commented on 23 Jan


BUG: 
If two sprites are handling touchstart and touchend events, sometimes one sprite receives BOTH touchend events, and the other sprite does not receive any touchend events.

Here is a gif demonstrating the effect: https://gfycat.com/PleasingIncompleteAardwolf
As you can see in the console, a sprite will receive a touchstart event, then remember the touch 'identifier' that is embedded in the event. All sprites receive ALL unrelated touchmove events, therefore the sprite must filter out events which pertain to itself by checking the identifier in each event (not printed to console). However, sometimes one sprite receives all the touchend events, including those that contain identifiers associated with the other sprites. These other sprites don't get their touchend events.

SOLUTION:
The workaround stated here involving adding checks to the processTouchStart and processTouchEnd:
http://www.html5gamedevs.com/topic/19273-can-container-get-touchup-event-when-touchdown-of-other-container-press/

Alternatively, perhaps all sprites should receive all touchend events, just like they receive all touchmove events, and allow each sprite to remember its own touchstart identifier, and then listen for a touchend which has the same identifier.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值