mirror of https://github.com/axmolengine/axmol.git
Adds getScene() to Node
helper function to get the Scene containing the Node
This commit is contained in:
parent
d35846b0d4
commit
4f435a8613
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue