make top sprite offset settable in BasedButtonSprite

This commit is contained in:
HJfod 2024-02-22 23:56:20 +02:00
parent 1e0a8c5e2f
commit 2825654361
2 changed files with 9 additions and 4 deletions

View file

@ -148,6 +148,7 @@ namespace geode {
int m_size;
int m_color;
cocos2d::CCNode* m_onTop = nullptr;
cocos2d::CCPoint m_topOffset = CCPointZero;
bool init(cocos2d::CCNode* ontop, BaseType type, int size, int color);
bool initWithSprite(
@ -157,7 +158,6 @@ namespace geode {
const char* sprName, float sprScale, BaseType type, int size, int color
);
cocos2d::CCPoint getTopOffset() const;
virtual cocos2d::CCSize getMaxTopSize() const;
virtual ~BasedButtonSprite();
@ -180,6 +180,11 @@ namespace geode {
cocos2d::CCNode* ontop, BaseType type, int size, int color
);
/**
* Set an offset to the top sprite
*/
void setTopOffset(CCPoint const& offset);
cocos2d::CCNode* getTopNode() const;
};

View file

@ -190,7 +190,7 @@ bool BasedButtonSprite::init(CCNode* ontop, BaseType type, int size, int color)
if (ontop) {
m_onTop = ontop;
m_onTop->setPosition(this->getContentSize() / 2 + this->getTopOffset());
m_onTop->setPosition(this->getContentSize() / 2 + m_topOffset);
limitNodeSize(m_onTop, this->getMaxTopSize(), m_onTop->getScale(), .1f);
this->addChild(m_onTop);
}
@ -202,8 +202,8 @@ CCSize BasedButtonSprite::getMaxTopSize() const {
return m_obContentSize - CCSize(18.f, 18.f);
}
CCPoint BasedButtonSprite::getTopOffset() const {
return { 0, 0 };
void BasedButtonSprite::setTopOffset(CCPoint const& offset) {
m_topOffset = offset;
}
bool BasedButtonSprite::initWithSprite(