Skip to content

Instantly share code, notes, and snippets.

@SpaghettDev
Last active December 17, 2023 15:12
Show Gist options
  • Save SpaghettDev/8c52d6fbb7b7f8668229b6dc923151e7 to your computer and use it in GitHub Desktop.
Save SpaghettDev/8c52d6fbb7b7f8668229b6dc923151e7 to your computer and use it in GitHub Desktop.
An FLalertLayer than actually registers touch events within nested CCMenus (Geometry Dash)
#include <cocos2d.h>
#include <gd.h>
class Layer : public gd::FLAlertLayer
{
public:
CCMenu* m_pMenu{};
void onEnter() override
{
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, cocos2d::kCCMenuHandlerPriority, true);
CCLayer::onEnter();
}
void onBtn(CCObject*) { std::cout << "called" << '\n'; }
bool init()
{
m_pMenu = CCMenu::create();
m_pLayer->addChild(m_pMenu);
// btn will get its touch events registed instead of doing jack shit
auto btn = gd::CCMenuItemSpriteExtra::create(
CCSprite::createWithSpriteFrameName("GJ_optionsTxt_001.png"),
this,
menu_selector(Layer::onBtn)
);
m_pMenu->addChild(btn);
return true;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment