Search code examples
c++objective-ccocos2d-iphonecocos2d-x

How to call a method of the first class of the second, by pressing the button?


I can not make a call to a method of a class from another class :rewrite the code cocos2d (objective-c) on cocos2d-x (c++)

Error:

c:\program files\microsoft visual studio 11.0\vc\include\xrefwrap(273): error C2562: std::_Pmd_caller<_Ret,_Arg0>::_Call_pmd: функция типа "void", возвращающая значение
1>          with
1>          [
1>              _Ret=void,
1>              _Arg0=cocos2d::Object
1>          ]
1>          c:\program files\microsoft visual studio 11.0\vc\include\xrefwrap(271): см. объявление "std::_Pmd_caller<_Ret,_Arg0>::_Call_pmd"
1>          with
1>          [
1>              _Ret=void,
1>              _Arg0=cocos2d::Object
1>          ]

Not become fully kidat.Tam 20 more lines of the same

HudLayer.cpp

CCMenuItem *button = CCMenuItemImage::create("1.png","1.png",menu_selector(HelloWorld::createSprite));

HelloWorld.cpp

void HelloWorld::createSprite(CCObject *sender)
{

    _sprite->initWithFile("bird.png");
    _sprite->setPosition(ccp(x,y));

}

Solution

  • In the IronMan.h you have to declare

    static void playClicked();

    In the Avenger.cpp you can use this method

     CCSize *screenSize   = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint pointOrigin  = CCDirector::sharedDirector()->getVisibleOrigin();
    float x = screenSize.width;
    float y = screenSize.height;*
    

    CCWidgetLayout* widgetLayout = CCWidgetLayout::create();

    addChild(widgetLayout);

    CCButton* playButton = CCButton::create("btn1.png", "btn2.png", "btn3.png");
    playButton->setPosition(x/1.2f,y/1.5f);
    playButton->setClickSelector(this,click_selector(IronMan::playClicked));
    widgetLayout->addChild(playButton,1);