helper function to get the Scene containing the Node
This commit is contained in:
Ricardo Quesada 2013-12-21 12:28:49 -08:00
Родитель d35846b0d4
Коммит 4f435a8613
4 изменённых файлов: 21 добавлений и 0 удалений

Просмотреть файл

@ -518,6 +518,13 @@ void Node::setShaderProgram(GLProgram *pShaderProgram)
_shaderProgram = pShaderProgram;
}
Scene* Node::getScene()
{
if(!_parent)
return nullptr;
return _parent->getScene();
}
Rect Node::getBoundingBox() const
{
Rect rect = Rect(0, 0, _contentSize.width, _contentSize.height);

Просмотреть файл

@ -53,6 +53,7 @@ class ActionManager;
class Component;
class ComponentContainer;
class EventDispatcher;
class Scene;
#ifdef CC_USE_PHYSICS
class PhysicsBody;
#endif
@ -910,6 +911,11 @@ public:
*/
virtual void visit();
/** Returns the Scene that contains the Node.
It returns `nullptr` if the node doesn't belong to any Scene.
This function recursively calls parent->getScene() until parent is a Scene object. The results are not cached. It is that the user caches the results in case this functions is being used inside a loop.
*/
virtual Scene* getScene();
/**
* Returns a "local" axis aligned bounding box of the node.

Просмотреть файл

@ -83,6 +83,11 @@ std::string Scene::getDescription() const
return StringUtils::format("<Scene | tag = %d>", _tag);
}
Scene* Scene::getScene()
{
return this;
}
#ifdef CC_USE_PHYSICS
Scene *Scene::createWithPhysics()
{

Просмотреть файл

@ -56,6 +56,8 @@ public:
static Scene *createWithPhysics();
#endif
// Overrides
virtual Scene *getScene() override;
#ifdef CC_USE_PHYSICS
public:
@ -76,6 +78,7 @@ protected:
#endif // CC_USE_PHYSICS
protected:
Scene();
virtual ~Scene();