alfonsocejudo / EasyNDK-for-cocos2dx3

An update to the original EasyNDK project for use with Cocos2d-x v3.0 and (hopefully) higher.
28 stars 14 forks source link

Sending message from native environment to C++ does not work #5

Open ngocpn57 opened 10 years ago

ngocpn57 commented 10 years ago

I'm using cocos2d-x 3.2 and I noticed EasyNDK can send message from C++ to native environment but the opposite direction is not working

I have this on the scene

NDKHelper::addSelector("TitleScene", "messageBetweenTitleSceneAndNative", CC_CALLBACK_2(TitleScene::messageSentFromMainToTitleScene, this), this);
void TitleScene::messageSentFromMainToTitleScene(Ref *sender, Value data){
    // some stuffs here
}

And this one in RootViewController.mm

[IOSNDKHelper setNDKReceiver:self];

[IOSNDKHelper sendMessage:@"messageSentFromMainToTitleScene" withParameters:nil];

The method messageSentFromMainToTitleScene is never called, and there is no error log in the output

I also tried to replace the first parameter of messageSentFromMainToTitleScene with type Node*, and a non-nil parameter in withParameters but still no luck

shauket commented 9 years ago

use messageSentFromMainToTitleScene in this way.

void TitleScene::messageSentFromMainToTitleScene(Node* sender, void *data){ // some stuffs here }

and call in this way

NDKHelper::AddSelector("TitleScene", "messageSentFromMainToTitleScene", callfuncND_selector(MenuUI::sharingCompleteCallback), this);

hope so it will work in your side let me know if it not worked. kindly pull latest ndk i have made some changes regarding removal of selectors with the name of groupName. just call function in destructor of your class NDKHelper::RemoveSelectorsInGroup();