void Title::MenuCreate(int posX,int posY,std::string _string,呼び出したい関数)←ここにコールバック関数を入れたい
{
//画面の幅を取る
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
// ボタンの枠の生成
Sprite* buttonframe = Sprite::create();
buttonframe->setTextureRect(Rect(0, 0, 110, 60));
buttonframe->setColor(Color3B::BLACK);
buttonframe->setPosition(Point(x, y));
this->addChild(buttonframe);
//ボタンの作成 Start
Sprite* startbutton = Sprite::create();
startbutton->setTextureRect(Rect(0, 0, 100, 50));
startbutton->setColor(Color3B::WHITE);
startbutton->setPosition(Point(x, y));
this->addChild(startbutton);
//ボタンの文字
auto label = Label::createWithSystemFont(_string, "arial", 24);
label->setColor(Color3B::RED);
auto buttonEvent = MenuItemLabel::create(label, CC_CALLBACK_1(呼び出したい関数, this));
//メニューの作成 menuの中にbuttonEventを入れる
Menu* menu = Menu::create(buttonEvent, NULL);
//pMenuを画面中央に配置
menu->setPosition(x,y);
this->addChild(menu);
}
//////////////////////////////////////////////////////////////////////////
ボタンを作る関数を作ってみようと思ったのですが
コールバック関数の中身を引数に入れる方法がイマイチ分かりません。
一応わかりやすいかと思って全文書きましたが太字の部分だけで言いたいことはわかると思います。
あと厚かましいかと思いますがもう少しプログラム良い書き方あったり、
わかりやすい方法があったらご指摘してくれたら嬉しいです
回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。