vendredi 13 avril 2018

Cocos2d-x CC_CALLBACK_X causes lint error in Android Studio

So I have returned to playing with cocos2d-x after a few months and created a new project (I am using Android Studio 3.0.1 and cocos2d-x-3.17). To be clear from the start, the project builds successfully and runs successfully. By that I mean that I navigate to de desired Scene and I am getting successful prints of touch events etc. The problem is that I am seeing a lot of annoying red error lint underlines when I use CC_CALLBACKS binding macros (with any of the 4 available).

For instance:

auto playItem = MenuItemImage::create("assets/res/MainMenuScene/img_button_play.png",
                                      "assets/res/MainMenuScene/img_button_play.png",
                                      CC_CALLBACK_1(MainMenuScene::goToGameScene, this));

Where this represents the MainMenuScene.cpp and the MainMenuScene::goToGameScene is declared in the MainMenuScene.h:

void goToGameScene(cocos2d::Ref *pSender);

and implemented as follows:

void MainMenuScene::goToGameScene(cocos2d::Ref *pSender) {
    auto scene = GameScene::createScene();
    Director::getInstance()->replaceScene(TransitionFade::create(1.0, scene));
}

The lint error I am getting is No matching function on MenuItemImage::create(...

This was the most basic example to share, but I am getting other errors with touch event listeners while assigning onTouch listeners via CC_CALLBACKs

If I replace the CC_CALLBACK macro with a lambda the lint error is gone. The question finally is, Has anyone experienced this in the past and knows how to fix this?

I'm pretty sure the lint errors can be suppressed somehow but I don't think that is the goal here, but rather to see why Android Studio is complaining and address that issue.

Aucun commentaire:

Enregistrer un commentaire