Android touch problem

Hi everyone. I have built test apk, but touches dont work. Where can be problem?

Listener init

touchListener->setSwallowTouches(false);
touchListener->onTouchEnded = Hero::touchUp;
touchListener->onTouchCancelled = Hero::touchUp;
_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);

touchUp

auto gm = GameManager::getInstance();
gm->mouseClicked = true;

Hero update

auto gm = GameManager::getInstance();
if (gm->mouseClicked) {
    this->setPositionX(this->getPositionX() + 20.0f);
}

Everything works when I use a mouse

I think your touch code could use some improvements. Maybe try something like this:

// touch events.
    auto listener = cocos2d::EventListenerTouchOneByOne::create();
    listener->setSwallowTouches(true);
    
    listener->onTouchBegan = [&](cocos2d::Touch* touch, cocos2d::Event* event)
    {
        if (!_gameObject->Instance()->getGameIsPaused())
        {
            cocos2d::Vec2 p = touch->getLocation();
            cocos2d::Rect rect = this->getBoundingBox();
            
            if(rect.containsPoint(p))
            {
                CornSprite::touchEvent(touch);
                return true;
            }
        }
        
        return false;
    };
    
    listener->onTouchEnded = [=](cocos2d::Touch* touch, cocos2d::Event* event)
    {
    };

Ok, onTouchBegan works, but the same code with onTouchEnded doesnot work. I dont see a problem. The same code should work onTouchEnded too.

auto touchListener = EventListenerTouchOneByOne::create();
touchListener->setSwallowTouches(true);
touchListener->onTouchEnded = [&](Touch* touch, Event* event) 
{
	GameManager::getInstance()->mouseClicked = true;
	return false;
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);

you need to return true;

It doesnt matter. In both case dont work.

Can you send me your listener code, all of it so I can test?

I ran this code o my Android device and it works for me. Plus my game uses this same listener approach and also works on Android.

temp2Proj.zip (485.8 KB)

My Classes and Resources.
Compile with

cocos compile -p android --android-studio -m release --ap android-22

Let me run cocos new ..., drop in your items and compile, deploy and test.

Ungine version is 3.16, maybe it is a problem?

Let me try