mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-23 07:57:51 -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;
|
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
|
* Get the first child that has the given sprite frame
|
||||||
* name either in the sprite or in the sprite inside
|
* 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);
|
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);
|
auto cache = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name);
|
||||||
if (!cache) return nullptr;
|
if (!cache) return false;
|
||||||
|
|
||||||
auto* texture = cache->getTexture();
|
auto* texture = cache->getTexture();
|
||||||
auto rect = cache->getRect();
|
auto rect = cache->getRect();
|
||||||
|
|
||||||
for (int i = 0; i < parent->getChildrenCount(); ++i) {
|
if (auto* spr = typeinfo_cast<CCSprite*>(node)) {
|
||||||
auto* child = parent->getChildren()->objectAtIndex(i);
|
if (spr->getTexture() == texture && spr->getTextureRect() == rect) {
|
||||||
if (auto* spr = typeinfo_cast<CCSprite*>(child)) {
|
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) {
|
if (spr->getTexture() == texture && spr->getTextureRect() == rect) {
|
||||||
return spr;
|
return true;
|
||||||
}
|
|
||||||
} 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 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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue