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

Bubbling in touch events #89

Open
zmeyc opened this issue Jan 12, 2017 · 4 comments
Open

Bubbling in touch events #89

zmeyc opened this issue Jan 12, 2017 · 4 comments

Comments

@zmeyc
Copy link
Contributor

zmeyc commented Jan 12, 2017

On iOS simulator TOUCH_UP and MOVE events are emitted once, but TOUCH_DOWN is emitted twice (with bubbling: true, then bubbling: false).

TOUCH_DOWN: bubbles=1
TOUCH_MOVE: bubbles=1
TOUCH_MOVE: bubbles=1
TOUCH_MOVE: bubbles=1
TOUCH_UP: bubbles=1
TOUCH_UP: bubbles=0

Steps to reproduce:

    _holder->addEventListener(TouchEvent::TOUCH_UP, CLOSURE(this, &GameScene::onTouchEvent));
    _holder->addEventListener(TouchEvent::MOVE, CLOSURE(this, &GameScene::onTouchEvent));
    _holder->addEventListener(TouchEvent::TOUCH_DOWN, CLOSURE(this, &GameScene::onTouchEvent));

void GameScene::onTouchEvent(Event *ev)
{
    if (ev->type == TouchEvent::TOUCH_DOWN)
        log::messageln("TOUCH_DOWN: bubbles=%d", (int)ev->bubbles);
    else if (ev->type == TouchEvent::MOVE)
        log::messageln("TOUCH_MOVE: bubbles=%d", (int)ev->bubbles);
    else if (ev->type == TouchEvent::TOUCH_UP)
        log::messageln("TOUCH_UP: bubbles=%d", (int)ev->bubbles);
}
@jordan-woyak
Copy link
Contributor

jordan-woyak commented Mar 22, 2017

This is an issue on more than just iOS. TOUCH_UP is emitted twice (not TOUCH_DOWN).

The second (bubbles:false) event is dispatched within "Actor::_onGlobalTouchUpEvent".

I can't make heads or tails of the intended logic within Actor involving _overred, _pressedButton, and _pressedOvered.
It looks like it might be trying to add handlers to generate TOUCH_UP/MOVE events on an Actor that received TOUCH_DOWN previously, regardless of the current mouse position.

I can't help but think this needs a bit of an overhaul. It seems to be designed around originally only supporting a single pointer perhaps?

Each Actor maintaining its own mouse button state seems wrong in general. Why is this being done?

@frankinshtein
Copy link
Contributor

It is known bug.
there is workaround: you should check if 'bubbles' flag = false

example:

void GameScene::onEvent(Event *ev)
{
     if (ev->type == TouchEvent::TOUCH_UP && ev->bubbles == false)
     { 
         someStuff();
     }
}

@frankinshtein
Copy link
Contributor

I can't help but think this needs a bit of an overhaul. It seems to be designed around originally only supporting a single pointer perhaps?

Each Actor maintaining its own mouse button state seems wrong in general. Why is this being done?

It is designed for multitouches. Thats why each actor has own state

@jordan-woyak
Copy link
Contributor

jordan-woyak commented Mar 22, 2017

It is designed for multitouches. Thats why each actor has own state

Yeah, but why is the state stored in each Actor? Why can't objects deriving from Actor register event handlers and deal with touch events normally on their own? It looks like the whole point of Actor keeping track of which pointer "overred" and "pressed" it is so it can register _onGlobalTouchMoveEvent and _onGlobalTouchUpEvent. Why are those handlers needed?

And then _overred is a pointer_index and _pressedButton is an array of pointer_index. So the Actor code can only remember a single "pointer" that "overred" or "pressed" it (per button). That doesn't seem multi-touch compliant.

TLDR: Why does Actor register touch event handlers at all? Why can't derived classes handle all the touch events as needed?

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

3 participants