mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-22 23:48:08 -05:00
isSpriteFrameName
This commit is contained in:
parent
07dd379611
commit
eea35568fe
2 changed files with 31 additions and 13 deletions
|
@ -737,6 +737,18 @@ namespace geode::cocos {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a node has the given sprite frame
|
||||
* name either in the sprite or in the sprite inside
|
||||
* the button.
|
||||
*
|
||||
* @param node Node to check
|
||||
* @param name Name of the sprite frame to search for
|
||||
* @returns True if the node has the given sprite frame
|
||||
* name
|
||||
*/
|
||||
bool isSpriteFrameName(cocos2d::CCNode* node, const char* name);
|
||||
|
||||
/**
|
||||
* Get the first child that has the given sprite frame
|
||||
* name either in the sprite or in the sprite inside
|
||||
|
|
|
@ -339,28 +339,34 @@ std::shared_ptr<WeakRefController> WeakRefPool::manage(CCObject* obj) {
|
|||
return m_pool.at(obj);
|
||||
}
|
||||
|
||||
CCNode* geode::cocos::getChildBySpriteFrameName(CCNode* parent, const char* name) {
|
||||
bool geode::cocos::isSpriteFrameName(CCNode* node, const char* name) {
|
||||
auto cache = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name);
|
||||
if (!cache) return nullptr;
|
||||
if (!cache) return false;
|
||||
|
||||
auto* texture = cache->getTexture();
|
||||
auto rect = cache->getRect();
|
||||
|
||||
for (int i = 0; i < parent->getChildrenCount(); ++i) {
|
||||
auto* child = parent->getChildren()->objectAtIndex(i);
|
||||
if (auto* spr = typeinfo_cast<CCSprite*>(child)) {
|
||||
if (auto* spr = typeinfo_cast<CCSprite*>(node)) {
|
||||
if (spr->getTexture() == texture && spr->getTextureRect() == rect) {
|
||||
return true;
|
||||
}
|
||||
} else if (auto* btn = typeinfo_cast<CCMenuItemSprite*>(node)) {
|
||||
auto* img = btn->getNormalImage();
|
||||
if (auto* spr = typeinfo_cast<CCSprite*>(img)) {
|
||||
if (spr->getTexture() == texture && spr->getTextureRect() == rect) {
|
||||
return spr;
|
||||
}
|
||||
} else if (auto* btn = typeinfo_cast<CCMenuItemSprite*>(child)) {
|
||||
auto* img = btn->getNormalImage();
|
||||
if (auto* spr = typeinfo_cast<CCSprite*>(img)) {
|
||||
if (spr->getTexture() == texture && spr->getTextureRect() == rect) {
|
||||
return btn;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
CCNode* geode::cocos::getChildBySpriteFrameName(CCNode* parent, const char* name) {
|
||||
for (auto child : CCArrayExt<CCNode*>(parent->getChildren())) {
|
||||
if (::isSpriteFrameName(static_cast<CCNode*>(child), name)) {
|
||||
return child;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue