0
\$\begingroup\$

I'm having trouble with a touch listener not picking up touch events on android, but doing fine in windows (mouse input). I've got a Node listening for touches (not a Layer), but from what I've been seeing around it seems having it on a Layer isn't a requirement anymore?

Setup

void DodgePlayerController::setupPlayerInput()
{
    CCLOG("DodgePlayerController::setupPlayerInput()");
    if (myPawn)
    {
        Pellet* myPellet = dynamic_cast<Pellet*>(myPawn);
        if (myPellet)
        {
            CCLOG("DodgePlayerController::setupPlayerInput() !!2!!");
            //setup the player input and events (should build some sort of player controller)
            auto listener = EventListenerTouchAllAtOnce::create();
            listener->onTouchesBegan = CC_CALLBACK_2(Pellet::setTargetPosition, myPellet);
            listener->onTouchesMoved = CC_CALLBACK_2(Pellet::setTargetPosition, myPellet);
            listener->onTouchesEnded = CC_CALLBACK_2(Pellet::clearTargetPosition, myPellet);
            listener->onTouchesCancelled = CC_CALLBACK_2(Pellet::clearTargetPosition, myPellet);

            auto dispatcher = getEventDispatcher();
            dispatcher->addEventListenerWithSceneGraphPriority(listener, this);
        }
    }
}

When logging on Android, I'm getting through both CCLOG messages correctly (I have a 'disablePlayerInput()' which isn't being called, so the listener shouldn't be removed). This all works fine in the windows application, but when I load it in Android the touches aren't picked up (Pellet::setTargetPosition also has a log message which doesn't get thrown in android).

Anyone know what I might be missing?

\$\endgroup\$
-1
\$\begingroup\$

Try to add setSwallowTouches (true); after creating the listener.

\$\endgroup\$
  • \$\begingroup\$ This answer would be improved by explaining to the asker what this function does and why it would solve the described problem. \$\endgroup\$ – Josh Apr 9 '15 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.