我爲uiButton的創建創建了類,有三個函數如下; 我創建了按鈕類,下面有3個函數類;addTouchEventListener的參數是什麼
void MyButtonClass::Create(const std::string &buttonImage, cocos2d::Layer *layer)
{
myButton = ui::Button::create(buttonImage, buttonImage);
layer->addChild(myButton, 100);
}
void MyButtonClass::SetPosition(float xPosition, float yPosition)
{
myButton->cocos2d::Node::setPosition(xPosition, yPosition);
}
void MyButtonClass::SetTouchListener(Ref *sender, SEL_TouchEvent *selector)//There is problem
{
myButton->addTouchEventListener(sender, selector);
}
如何設置TouchListener?我查看了庫中的參數,但它不起作用。
例如從我的gamescene創建按鈕;
button.Create("Play.png", this);
button.SetPosition(100, 200);
button.SetTouchListener(CC_CALLBACK_1(GameScene::Play, this));//Exception: No viable conversion from '__bind<void (GameScene::*)(cocos2d::Ref *), GameScene *, std::__1::placeholders::__ph<1> &>' to 'cocos2d::Ref *'
那麼如何在我的函數中使用'ccWidgetTouchCallback'參數。我的類不是從':: cocos2d :: ui :: Button'或':: cocos2d :: ui :: Widget'繼承的。 –
您可以在'myButton'對象上調用'addTouchEventListener'。你只是在'myButton'中使用'addTouchEventListener'的不正確的重載。回調可以綁定到任何東西,包括你自己班級的方法。 – namezero
我已經知道了,如何設置其他課程的活動?我的uiButton在myButtonClass中是私有的。我的SetTouchListener方法是公開的,我想爲此方法設置自定義回調。 –