Skip to content

Commit

Permalink
Update popup tutorial to use initAnchored and m_mainLayer (#50)
Browse files Browse the repository at this point in the history
* Update popup tutorial to use initAnchored and m_mainLayer

* use addchildatposition

---------

Co-authored-by: mat <26722564+matcool@users.noreply.github.com>
  • Loading branch information
Kingminer7 and matcool authored Oct 30, 2024
1 parent a772aa5 commit 676e406
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions tutorials/popup.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,20 @@ However, what if you want to make a popup that's more complex? For example, some
class MyPopup : public geode::Popup<std::string const&> {
protected:
bool setup(std::string const& value) override {
auto winSize = CCDirector::sharedDirector()->getWinSize();

// convenience function provided by Popup
// for adding/setting a title to the popup
this->setTitle("Hi mom!");

auto label = CCLabelBMFont::create(value.c_str(), "bigFont.fnt");
label->setPosition(winSize / 2);
this->addChild(label);
m_mainLayer->addChildAtPosition(label, Anchor::Center);

return true;
}

public:
static MyPopup* create(std::string const& text) {
auto ret = new MyPopup();
if (ret->init(240.f, 160.f, text)) {
if (ret->initAnchored(240.f, 160.f, text)) {
ret->autorelease();
return ret;
}
Expand Down

0 comments on commit 676e406

Please sign in to comment.