Cocos2dx Reader Scene not responding to Touch

Cocos2dx 3.16
Android Studio 3.0

Hello, I made a scene using the cocos2dx to creator c++ plugin and it loads fine on my LG G4 i can hear the music and buttons press in and out showing taps are felt. The issue is that my button will not do anything it reacts visibly but does not do the director end function i have tried various things and cannot figure out why my scene will not respond.

#include <reader/CreatorReader.h>
#include "MMScene.h"
#include "SimpleAudioEngine.h"
#include "ui/CocosGUI.h"
#include <ui/UILayout.h>


using namespace cocos2d;

USING_NS_CC;

Scene* MMScene::createScene()
{
    creator::CreatorReader* reader = creator::CreatorReader::createWithFilename("creator/MDiceX/MMScene.ccreator");

    // will create the needed spritesheets + design resolution
    reader->setup();

    // get the scene graph
    Scene * MMScene = reader->getSceneGraph();

    // ...and use it
    Director::getInstance()->replaceScene(MMScene);



    CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("Music/achaidhcheide.mp3");

// return the scene
    return MMScene;
}

// on "init" you need to initialize your instance
bool MMScene::init() {




    //////////////////////////////
    // 1. super init first
    if (!Scene::init()) {
        return false;
    }

    auto FirstStartUp = ( ui::Layout * )this->getChildByName("FirstStartUp" );

    FirstStartUp->setTouchEnabled(false);
    FirstStartUp->setSwallowTouches(false);

    FirstStartUp->setVisible(false);
    FirstStartUp->setEnabled(false);

    auto MMLeaderBoardButton = ( ui::Button * )this->getChildByName("MMLeaderBoardButton" );

    MMLeaderBoardButton->addTouchEventListener([&](Ref* sender, Widget::TouchEventType type){
        switch (type)
        {
            case ui::Widget::TouchEventType::BEGAN:
               
                break;
            case ui::Widget::TouchEventType::ENDED:

                Director::getInstance()->end();

                break;
            default:
                break;
        }
    });

    this->addChild(MMLeaderBoardButton);


    auto visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();


}

So your issue is that, MMLeaderBoardButton can not receive touch events, right? Could you please share me the creator project? I will take a look. Thanks.

@ManaInfested i have received your creator project, i will ask @drelaptop to take a look.

it’s my pleasure to take this, I will research it in detail.

@ManaInfested Sorry for a long response, I use the code and resource your supplied, then I found the bool MMScene::init() function never been called, so your addTouchEventListener didn’t work.

researching the code we can found the init function will be called only when the static __TYPE__* create() be called.

I fixed your issue and push the code into github, see this:

Cocos2d-x version: Github latest
Creator version: 1.8.1
build by CMake & Xcode 9.2

1 Like

Thank you sooooo much!!! ^_^!!