App crash when trying to implement touch functionality

I’m trying to do a simple touch and move based on this wiki entry, but the program crashes right away with “Assertion failed” error, with a reason “CCEventListenerTouch.cpp, Line 89, Expression: false”.

Here’s the code I wrote:

bool MainLayer::init()
{
    Sprite* tile = Sprite::create("tile.png");
    this->addChild(tile);
    auto listener = EventListenerTouchOneByOne::create();
    listener->setSwallowTouches(true);

    listener->onTouchMoved = [](Touch* touch, Event* event)
    {
        tile->setPosition(tile->getPosition() + touch->getDelta());
    };

    // If I comment this line out, it won't crash but touch won't work either...
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, tile);

    return true;
}

What could be causing the crash?

EDIT: I’m using Cocos2D-X 3.2. It crashes on both Win32 and WP8, haven’t tried any other ports.

1 Like

This happens because you didn’t implement EventListenerTouchOneByOne::onTouchBegan function.

1 Like

I just found that out myself and came here to answer my own question. :slight_smile: Thanks anyway!

Too slow you were, Luke.