2010-12-18 16:12:59 +08:00
|
|
|
/****************************************************************************
|
2011-03-19 14:45:51 +08:00
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
|
|
|
Copyright (c) 2009 Valentin Milea
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2011-07-01 15:48:05 +08:00
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
2010-12-18 16:12:59 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2013-08-26 01:50:29 +08:00
|
|
|
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/CCNode.h"
|
2013-08-26 01:50:29 +08:00
|
|
|
|
|
|
|
#include <algorithm>
|
2014-06-11 16:57:43 +08:00
|
|
|
#include <string>
|
2014-06-17 11:43:03 +08:00
|
|
|
#include <regex>
|
2013-08-26 01:50:29 +08:00
|
|
|
|
2014-04-30 08:37:36 +08:00
|
|
|
#include "base/CCDirector.h"
|
|
|
|
#include "base/CCScheduler.h"
|
|
|
|
#include "base/CCTouch.h"
|
|
|
|
#include "base/CCEventDispatcher.h"
|
|
|
|
#include "base/CCEvent.h"
|
|
|
|
#include "base/CCEventTouch.h"
|
2014-05-17 05:36:00 +08:00
|
|
|
#include "base/ccCArray.h"
|
2014-08-07 15:23:31 +08:00
|
|
|
#include "base/CCCamera.h"
|
2014-05-09 06:43:12 +08:00
|
|
|
#include "2d/CCGrid.h"
|
|
|
|
#include "2d/CCActionManager.h"
|
2014-05-17 05:36:00 +08:00
|
|
|
#include "base/CCScriptSupport.h"
|
2014-05-02 07:42:35 +08:00
|
|
|
#include "2d/CCScene.h"
|
2014-05-09 06:43:12 +08:00
|
|
|
#include "2d/CCComponent.h"
|
|
|
|
#include "2d/CCComponentContainer.h"
|
2014-05-09 09:01:48 +08:00
|
|
|
#include "renderer/CCGLProgram.h"
|
|
|
|
#include "renderer/CCGLProgramState.h"
|
2014-05-09 06:43:12 +08:00
|
|
|
#include "math/TransformUtils.h"
|
|
|
|
|
|
|
|
#include "deprecated/CCString.h"
|
2013-08-27 09:04:51 +08:00
|
|
|
|
2013-12-26 23:55:05 +08:00
|
|
|
#if CC_USE_PHYSICS
|
2014-04-27 01:35:57 +08:00
|
|
|
#include "physics/CCPhysicsBody.h"
|
2013-09-30 13:02:17 +08:00
|
|
|
#endif
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
|
2012-03-23 10:26:36 +08:00
|
|
|
#if CC_NODE_RENDER_SUBPIXEL
|
2010-07-20 14:29:18 +08:00
|
|
|
#define RENDER_IN_SUBPIXEL
|
|
|
|
#else
|
2013-04-13 15:18:54 +08:00
|
|
|
#define RENDER_IN_SUBPIXEL(__ARGS__) (ceil(__ARGS__))
|
2010-07-20 14:29:18 +08:00
|
|
|
#endif
|
2010-12-18 16:12:59 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_BEGIN
|
2010-12-18 16:12:59 +08:00
|
|
|
|
2014-01-22 01:26:58 +08:00
|
|
|
bool nodeComparisonLess(Node* n1, Node* n2)
|
2013-09-01 06:18:28 +08:00
|
|
|
{
|
2014-01-22 01:26:58 +08:00
|
|
|
return( n1->getLocalZOrder() < n2->getLocalZOrder() ||
|
|
|
|
( n1->getLocalZOrder() == n2->getLocalZOrder() && n1->getOrderOfArrival() < n2->getOrderOfArrival() )
|
2013-09-01 06:18:28 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-04-04 21:58:04 +08:00
|
|
|
// XXX: Yes, nodes might have a sort problem once every 15 days if the game runs at 60 FPS and each frame sprites are reordered.
|
2014-03-25 15:07:11 +08:00
|
|
|
int Node::s_globalOrderOfArrival = 1;
|
2012-03-14 14:55:17 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Node::Node(void)
|
2013-06-15 14:03:30 +08:00
|
|
|
: _rotationX(0.0f)
|
|
|
|
, _rotationY(0.0f)
|
2014-02-23 11:16:42 +08:00
|
|
|
, _rotationZ_X(0.0f)
|
|
|
|
, _rotationZ_Y(0.0f)
|
2013-06-15 14:03:30 +08:00
|
|
|
, _scaleX(1.0f)
|
|
|
|
, _scaleY(1.0f)
|
2014-02-23 11:16:42 +08:00
|
|
|
, _scaleZ(1.0f)
|
|
|
|
, _positionZ(0.0f)
|
2014-05-15 01:07:09 +08:00
|
|
|
, _position(Vec2::ZERO)
|
2013-06-15 14:03:30 +08:00
|
|
|
, _skewX(0.0f)
|
|
|
|
, _skewY(0.0f)
|
2014-05-15 01:07:09 +08:00
|
|
|
, _anchorPointInPoints(Vec2::ZERO)
|
|
|
|
, _anchorPoint(Vec2::ZERO)
|
2013-07-12 14:47:36 +08:00
|
|
|
, _contentSize(Size::ZERO)
|
2014-01-14 04:52:07 +08:00
|
|
|
, _useAdditionalTransform(false)
|
2013-07-29 14:07:57 +08:00
|
|
|
, _transformDirty(true)
|
|
|
|
, _inverseDirty(true)
|
2014-03-01 08:10:48 +08:00
|
|
|
, _transformUpdated(true)
|
2011-06-10 17:51:37 +08:00
|
|
|
// children (lazy allocs)
|
|
|
|
// lazy alloc
|
2014-01-19 03:35:27 +08:00
|
|
|
, _localZOrder(0)
|
|
|
|
, _globalZOrder(0)
|
2013-12-18 17:47:20 +08:00
|
|
|
, _parent(nullptr)
|
2013-06-15 14:03:30 +08:00
|
|
|
// "whole screen" objects. like Scenes and Layers, should set _ignoreAnchorPointForPosition to true
|
2013-08-29 03:42:25 +08:00
|
|
|
, _tag(Node::INVALID_TAG)
|
2011-06-10 17:51:37 +08:00
|
|
|
// userData is always inited as nil
|
2013-12-18 17:47:20 +08:00
|
|
|
, _userData(nullptr)
|
|
|
|
, _userObject(nullptr)
|
2014-05-09 06:43:12 +08:00
|
|
|
, _glProgramState(nullptr)
|
2013-06-15 14:03:30 +08:00
|
|
|
, _orderOfArrival(0)
|
|
|
|
, _running(false)
|
|
|
|
, _visible(true)
|
|
|
|
, _ignoreAnchorPointForPosition(false)
|
|
|
|
, _reorderChildDirty(false)
|
|
|
|
, _isTransitionFinished(false)
|
2014-02-20 16:40:46 +08:00
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
2013-06-15 14:03:30 +08:00
|
|
|
, _updateScriptHandler(0)
|
2014-02-20 16:40:46 +08:00
|
|
|
#endif
|
2013-12-18 17:47:20 +08:00
|
|
|
, _componentContainer(nullptr)
|
2013-12-26 23:55:05 +08:00
|
|
|
#if CC_USE_PHYSICS
|
2013-09-30 13:02:17 +08:00
|
|
|
, _physicsBody(nullptr)
|
2014-06-27 17:30:21 +08:00
|
|
|
, _physicsScaleStartX(1.0f)
|
|
|
|
, _physicsScaleStartY(1.0f)
|
2013-09-30 13:02:17 +08:00
|
|
|
#endif
|
2013-12-06 18:07:16 +08:00
|
|
|
, _displayedOpacity(255)
|
|
|
|
, _realOpacity(255)
|
|
|
|
, _displayedColor(Color3B::WHITE)
|
|
|
|
, _realColor(Color3B::WHITE)
|
|
|
|
, _cascadeColorEnabled(false)
|
|
|
|
, _cascadeOpacityEnabled(false)
|
2014-05-31 07:42:05 +08:00
|
|
|
, _usingNormalizedPosition(false)
|
2014-06-11 16:57:43 +08:00
|
|
|
, _name("")
|
|
|
|
, _hashOfName(0)
|
2014-08-07 15:23:31 +08:00
|
|
|
, _cameraMask(1)
|
2010-12-18 16:12:59 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// set default scheduler and actionManager
|
2013-07-12 06:24:23 +08:00
|
|
|
Director *director = Director::getInstance();
|
2013-06-15 14:03:30 +08:00
|
|
|
_actionManager = director->getActionManager();
|
|
|
|
_actionManager->retain();
|
|
|
|
_scheduler = director->getScheduler();
|
|
|
|
_scheduler->retain();
|
2013-10-26 15:04:01 +08:00
|
|
|
_eventDispatcher = director->getEventDispatcher();
|
|
|
|
_eventDispatcher->retain();
|
|
|
|
|
2014-02-20 16:40:46 +08:00
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
2013-12-18 17:47:20 +08:00
|
|
|
ScriptEngineProtocol* engine = ScriptEngineManager::getInstance()->getScriptEngine();
|
|
|
|
_scriptType = engine != nullptr ? engine->getScriptType() : kScriptTypeNone;
|
2014-02-20 16:40:46 +08:00
|
|
|
#endif
|
2014-05-15 01:07:09 +08:00
|
|
|
_transform = _inverse = _additionalTransform = Mat4::IDENTITY;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
2012-03-14 18:11:25 +08:00
|
|
|
|
2013-07-17 09:16:04 +08:00
|
|
|
Node::~Node()
|
2010-12-18 16:12:59 +08:00
|
|
|
{
|
2013-08-22 11:05:06 +08:00
|
|
|
CCLOGINFO( "deallocing Node: %p - tag: %i", this, _tag );
|
2012-09-21 00:21:24 +08:00
|
|
|
|
2014-02-20 16:40:46 +08:00
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_updateScriptHandler)
|
2012-12-10 13:48:27 +08:00
|
|
|
{
|
2013-07-22 17:24:54 +08:00
|
|
|
ScriptEngineManager::getInstance()->getScriptEngine()->removeScriptHandler(_updateScriptHandler);
|
2012-12-10 13:48:27 +08:00
|
|
|
}
|
2014-02-20 16:40:46 +08:00
|
|
|
#endif
|
2010-07-14 10:36:26 +08:00
|
|
|
|
2014-03-28 14:09:51 +08:00
|
|
|
// User object has to be released before others, since userObject may have a weak reference of this node
|
|
|
|
// It may invoke `node->stopAllAction();` while `_actionManager` is null if the next line is after `CC_SAFE_RELEASE_NULL(_actionManager)`.
|
|
|
|
CC_SAFE_RELEASE_NULL(_userObject);
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// attributes
|
2014-05-09 06:43:12 +08:00
|
|
|
CC_SAFE_RELEASE_NULL(_glProgramState);
|
2010-07-14 10:36:26 +08:00
|
|
|
|
2013-11-28 16:02:03 +08:00
|
|
|
for (auto& child : _children)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-19 09:45:21 +08:00
|
|
|
child->_parent = nullptr;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2010-07-14 10:36:26 +08:00
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
removeAllComponents();
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_DELETE(_componentContainer);
|
2013-09-03 18:22:03 +08:00
|
|
|
|
2013-12-26 23:55:05 +08:00
|
|
|
#if CC_USE_PHYSICS
|
2014-02-27 13:35:37 +08:00
|
|
|
setPhysicsBody(nullptr);
|
2014-03-27 04:12:44 +08:00
|
|
|
|
2013-09-30 13:02:17 +08:00
|
|
|
#endif
|
2014-03-28 14:43:44 +08:00
|
|
|
|
|
|
|
CC_SAFE_RELEASE_NULL(_actionManager);
|
|
|
|
CC_SAFE_RELEASE_NULL(_scheduler);
|
|
|
|
|
|
|
|
_eventDispatcher->removeEventListenersForTarget(this);
|
|
|
|
|
2014-03-28 03:29:28 +08:00
|
|
|
#if CC_NODE_DEBUG_VERIFY_EVENT_LISTENERS && COCOS2D_DEBUG > 0
|
|
|
|
_eventDispatcher->debugCheckNodeHasNoEventListenersOnDestruction(this);
|
|
|
|
#endif
|
2014-03-27 04:12:44 +08:00
|
|
|
|
2014-04-08 08:05:42 +08:00
|
|
|
CCASSERT(!_running, "Node still marked as running on node destruction! Was base class onExit() called in derived class onExit() implementations?");
|
2014-03-27 04:12:44 +08:00
|
|
|
CC_SAFE_RELEASE(_eventDispatcher);
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool Node::init()
|
2013-02-27 09:38:30 +08:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-04 08:22:15 +08:00
|
|
|
float Node::getSkewX() const
|
2011-07-01 15:48:05 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _skewX;
|
2011-07-01 15:48:05 +08:00
|
|
|
}
|
|
|
|
|
2014-02-27 15:12:57 +08:00
|
|
|
void Node::setSkewX(float skewX)
|
2011-07-01 15:48:05 +08:00
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_skewX == skewX)
|
|
|
|
return;
|
|
|
|
|
2014-06-24 10:33:21 +08:00
|
|
|
#if CC_USE_PHYSICS
|
|
|
|
if (_physicsBody != nullptr)
|
|
|
|
{
|
|
|
|
CCLOG("Node WARNING: PhysicsBody doesn't support setSkewX");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-02-27 15:12:57 +08:00
|
|
|
_skewX = skewX;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2011-07-01 15:48:05 +08:00
|
|
|
}
|
|
|
|
|
2013-07-04 08:22:15 +08:00
|
|
|
float Node::getSkewY() const
|
2011-07-01 15:48:05 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _skewY;
|
2011-07-01 15:48:05 +08:00
|
|
|
}
|
|
|
|
|
2014-02-27 15:12:57 +08:00
|
|
|
void Node::setSkewY(float skewY)
|
2011-07-01 15:48:05 +08:00
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_skewY == skewY)
|
|
|
|
return;
|
|
|
|
|
2014-06-24 10:33:21 +08:00
|
|
|
#if CC_USE_PHYSICS
|
|
|
|
if (_physicsBody != nullptr)
|
|
|
|
{
|
|
|
|
CCLOG("Node WARNING: PhysicsBody doesn't support setSkewY");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-02-27 15:12:57 +08:00
|
|
|
_skewY = skewY;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2011-07-01 15:48:05 +08:00
|
|
|
}
|
|
|
|
|
2010-12-18 16:12:59 +08:00
|
|
|
|
|
|
|
/// zOrder setter : private method
|
2010-07-14 10:36:26 +08:00
|
|
|
/// used internally to alter the zOrder variable. DON'T call this method manually
|
2014-01-19 03:35:27 +08:00
|
|
|
void Node::_setLocalZOrder(int z)
|
2010-07-14 10:36:26 +08:00
|
|
|
{
|
2014-01-19 03:35:27 +08:00
|
|
|
_localZOrder = z;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
2014-01-19 03:35:27 +08:00
|
|
|
void Node::setLocalZOrder(int z)
|
2012-03-16 13:42:53 +08:00
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_localZOrder == z)
|
|
|
|
return;
|
|
|
|
|
2014-01-19 03:35:27 +08:00
|
|
|
_localZOrder = z;
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_parent)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_parent->reorderChild(this, z);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2014-01-19 03:35:27 +08:00
|
|
|
|
2013-10-26 15:04:01 +08:00
|
|
|
_eventDispatcher->setDirtyForNode(this);
|
2012-03-16 13:42:53 +08:00
|
|
|
}
|
|
|
|
|
2014-01-22 02:10:50 +08:00
|
|
|
void Node::setGlobalZOrder(float globalZOrder)
|
2014-01-21 10:23:05 +08:00
|
|
|
{
|
2014-01-22 02:10:50 +08:00
|
|
|
if (_globalZOrder != globalZOrder)
|
2014-01-21 10:23:05 +08:00
|
|
|
{
|
2014-01-22 02:10:50 +08:00
|
|
|
_globalZOrder = globalZOrder;
|
2014-01-21 10:23:05 +08:00
|
|
|
_eventDispatcher->setDirtyForNode(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-18 16:12:59 +08:00
|
|
|
/// rotation getter
|
2013-07-04 08:22:15 +08:00
|
|
|
float Node::getRotation() const
|
2010-12-18 16:12:59 +08:00
|
|
|
{
|
2014-02-23 11:16:42 +08:00
|
|
|
CCASSERT(_rotationZ_X == _rotationZ_Y, "CCNode#rotation. RotationX != RotationY. Don't know which one to return");
|
|
|
|
return _rotationZ_X;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// rotation setter
|
2014-02-27 15:12:57 +08:00
|
|
|
void Node::setRotation(float rotation)
|
2010-07-12 17:56:06 +08:00
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_rotationZ_X == rotation)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_rotationZ_X = _rotationZ_Y = rotation;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
|
|
|
|
2013-12-26 23:55:05 +08:00
|
|
|
#if CC_USE_PHYSICS
|
2014-06-27 17:30:21 +08:00
|
|
|
if (!_physicsBody || !_physicsBody->_rotationResetTag)
|
2013-09-30 13:02:17 +08:00
|
|
|
{
|
2014-06-27 17:30:21 +08:00
|
|
|
updatePhysicsBodyRotation(getScene());
|
2013-09-30 13:02:17 +08:00
|
|
|
}
|
|
|
|
#endif
|
2012-11-14 18:05:15 +08:00
|
|
|
}
|
|
|
|
|
2014-02-23 11:16:42 +08:00
|
|
|
float Node::getRotationSkewX() const
|
|
|
|
{
|
|
|
|
return _rotationZ_X;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void Node::setRotation3D(const Vec3& rotation)
|
2014-02-23 11:16:42 +08:00
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_rotationX == rotation.x &&
|
|
|
|
_rotationY == rotation.y &&
|
|
|
|
_rotationZ_X == rotation.z)
|
|
|
|
return;
|
|
|
|
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2014-02-23 11:16:42 +08:00
|
|
|
|
|
|
|
_rotationX = rotation.x;
|
|
|
|
_rotationY = rotation.y;
|
|
|
|
|
|
|
|
// rotation Z is decomposed in 2 to simulate Skew for Flash animations
|
|
|
|
_rotationZ_Y = _rotationZ_X = rotation.z;
|
|
|
|
|
|
|
|
#if CC_USE_PHYSICS
|
2014-06-24 10:33:21 +08:00
|
|
|
if (_physicsBody != nullptr)
|
2014-02-23 11:16:42 +08:00
|
|
|
{
|
2014-06-24 10:33:21 +08:00
|
|
|
CCLOG("Node WARNING: PhysicsBody doesn't support setRotation3D");
|
2014-02-23 11:16:42 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec3 Node::getRotation3D() const
|
2012-11-14 18:05:15 +08:00
|
|
|
{
|
2014-02-23 11:16:42 +08:00
|
|
|
// rotation Z is decomposed in 2 to simulate Skew for Flash animations
|
|
|
|
CCASSERT(_rotationZ_X == _rotationZ_Y, "_rotationZ_X != _rotationZ_Y");
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
return Vec3(_rotationX,_rotationY,_rotationZ_X);
|
2012-11-14 18:05:15 +08:00
|
|
|
}
|
|
|
|
|
2014-02-27 15:12:57 +08:00
|
|
|
void Node::setRotationSkewX(float rotationX)
|
2012-11-14 18:05:15 +08:00
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_rotationZ_X == rotationX)
|
|
|
|
return;
|
|
|
|
|
2014-06-23 13:55:52 +08:00
|
|
|
#if CC_USE_PHYSICS
|
|
|
|
if (_physicsBody != nullptr)
|
|
|
|
{
|
|
|
|
CCLOG("Node WARNING: PhysicsBody doesn't support setRotationSkewX");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-02-27 15:12:57 +08:00
|
|
|
_rotationZ_X = rotationX;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2012-11-14 18:05:15 +08:00
|
|
|
}
|
|
|
|
|
2014-02-23 11:16:42 +08:00
|
|
|
float Node::getRotationSkewY() const
|
2012-11-14 18:05:15 +08:00
|
|
|
{
|
2014-02-23 11:16:42 +08:00
|
|
|
return _rotationZ_Y;
|
2012-11-14 18:05:15 +08:00
|
|
|
}
|
|
|
|
|
2014-02-23 11:16:42 +08:00
|
|
|
void Node::setRotationSkewY(float rotationY)
|
2012-11-14 18:05:15 +08:00
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_rotationZ_Y == rotationY)
|
|
|
|
return;
|
|
|
|
|
2014-06-23 13:55:52 +08:00
|
|
|
#if CC_USE_PHYSICS
|
|
|
|
if (_physicsBody != nullptr)
|
|
|
|
{
|
|
|
|
CCLOG("Node WARNING: PhysicsBody doesn't support setRotationSkewY");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-02-23 11:16:42 +08:00
|
|
|
_rotationZ_Y = rotationY;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// scale getter
|
2013-07-04 08:22:15 +08:00
|
|
|
float Node::getScale(void) const
|
2010-07-12 17:56:06 +08:00
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT( _scaleX == _scaleY, "CCNode#scale. ScaleX != ScaleY. Don't know which one to return");
|
2013-06-15 14:03:30 +08:00
|
|
|
return _scaleX;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// scale setter
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::setScale(float scale)
|
2010-07-12 17:56:06 +08:00
|
|
|
{
|
2014-06-24 10:05:52 +08:00
|
|
|
if (_scaleX == scale && _scaleY == scale && _scaleZ == scale)
|
2014-02-27 15:12:57 +08:00
|
|
|
return;
|
2014-06-23 13:55:52 +08:00
|
|
|
|
2014-03-01 05:48:00 +08:00
|
|
|
_scaleX = _scaleY = _scaleZ = scale;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2014-06-27 17:30:21 +08:00
|
|
|
|
|
|
|
#if CC_USE_PHYSICS
|
|
|
|
updatePhysicsBodyTransform(getScene());
|
|
|
|
#endif
|
2010-07-12 17:56:06 +08:00
|
|
|
}
|
2010-12-18 16:12:59 +08:00
|
|
|
|
|
|
|
/// scaleX getter
|
2013-07-04 08:22:15 +08:00
|
|
|
float Node::getScaleX() const
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _scaleX;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
2013-10-08 15:57:34 +08:00
|
|
|
/// scale setter
|
|
|
|
void Node::setScale(float scaleX,float scaleY)
|
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_scaleX == scaleX && _scaleY == scaleY)
|
|
|
|
return;
|
|
|
|
|
2013-10-08 15:57:34 +08:00
|
|
|
_scaleX = scaleX;
|
|
|
|
_scaleY = scaleY;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2014-06-27 17:30:21 +08:00
|
|
|
|
|
|
|
#if CC_USE_PHYSICS
|
|
|
|
updatePhysicsBodyTransform(getScene());
|
|
|
|
#endif
|
2013-10-08 15:57:34 +08:00
|
|
|
}
|
|
|
|
|
2010-12-18 16:12:59 +08:00
|
|
|
/// scaleX setter
|
2014-02-27 15:12:57 +08:00
|
|
|
void Node::setScaleX(float scaleX)
|
2010-07-12 17:56:06 +08:00
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_scaleX == scaleX)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_scaleX = scaleX;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2014-06-27 17:30:21 +08:00
|
|
|
|
|
|
|
#if CC_USE_PHYSICS
|
|
|
|
updatePhysicsBodyTransform(getScene());
|
|
|
|
#endif
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
2010-12-18 16:12:59 +08:00
|
|
|
|
|
|
|
/// scaleY getter
|
2013-07-04 08:22:15 +08:00
|
|
|
float Node::getScaleY() const
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _scaleY;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
2010-07-12 17:56:06 +08:00
|
|
|
|
2014-02-23 11:16:42 +08:00
|
|
|
/// scaleY setter
|
2014-02-27 15:12:57 +08:00
|
|
|
void Node::setScaleZ(float scaleZ)
|
2014-02-23 11:16:42 +08:00
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_scaleZ == scaleZ)
|
|
|
|
return;
|
|
|
|
|
2014-06-24 10:33:21 +08:00
|
|
|
#if CC_USE_PHYSICS
|
|
|
|
if (_physicsBody != nullptr)
|
|
|
|
{
|
|
|
|
CCLOG("Node WARNING: PhysicsBody doesn't support setScaleZ");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-02-27 15:12:57 +08:00
|
|
|
_scaleZ = scaleZ;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2014-02-23 11:16:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// scaleY getter
|
|
|
|
float Node::getScaleZ() const
|
|
|
|
{
|
|
|
|
return _scaleZ;
|
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// scaleY setter
|
2014-02-27 15:12:57 +08:00
|
|
|
void Node::setScaleY(float scaleY)
|
2010-07-12 17:56:06 +08:00
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_scaleY == scaleY)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_scaleY = scaleY;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2014-06-27 17:30:21 +08:00
|
|
|
|
|
|
|
#if CC_USE_PHYSICS
|
|
|
|
updatePhysicsBodyTransform(getScene());
|
|
|
|
#endif
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
2014-02-23 11:16:42 +08:00
|
|
|
|
2010-12-18 16:12:59 +08:00
|
|
|
/// position getter
|
2014-05-15 01:07:09 +08:00
|
|
|
const Vec2& Node::getPosition() const
|
2010-12-18 16:12:59 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _position;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// position setter
|
2014-05-15 01:07:09 +08:00
|
|
|
void Node::setPosition(const Vec2& position)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_position.equals(position))
|
|
|
|
return;
|
|
|
|
|
|
|
|
_position = position;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2014-05-31 07:42:05 +08:00
|
|
|
_usingNormalizedPosition = false;
|
2014-03-01 08:10:48 +08:00
|
|
|
|
2013-12-26 23:55:05 +08:00
|
|
|
#if CC_USE_PHYSICS
|
2014-06-27 17:30:21 +08:00
|
|
|
if (!_physicsBody || !_physicsBody->_positionResetTag)
|
2013-09-30 13:02:17 +08:00
|
|
|
{
|
2014-06-27 17:30:21 +08:00
|
|
|
updatePhysicsBodyPosition(getScene());
|
2013-09-30 13:02:17 +08:00
|
|
|
}
|
|
|
|
#endif
|
2010-12-31 14:56:24 +08:00
|
|
|
}
|
|
|
|
|
2013-07-04 08:22:15 +08:00
|
|
|
void Node::getPosition(float* x, float* y) const
|
2012-02-02 10:39:19 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
*x = _position.x;
|
|
|
|
*y = _position.y;
|
2012-02-02 10:39:19 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::setPosition(float x, float y)
|
2012-02-02 10:39:19 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
setPosition(Vec2(x, y));
|
2012-02-02 10:39:19 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void Node::setPosition3D(const Vec3& position)
|
2013-01-21 16:26:02 +08:00
|
|
|
{
|
2014-02-23 11:16:42 +08:00
|
|
|
_positionZ = position.z;
|
2014-05-15 01:07:09 +08:00
|
|
|
setPosition(Vec2(position.x, position.y));
|
2013-01-21 16:26:02 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec3 Node::getPosition3D() const
|
2013-01-21 16:26:02 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec3 ret;
|
2014-02-23 11:16:42 +08:00
|
|
|
ret.x = _position.x;
|
|
|
|
ret.y = _position.y;
|
|
|
|
ret.z = _positionZ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
float Node::getPositionX() const
|
|
|
|
{
|
|
|
|
return _position.x;
|
2013-01-21 16:26:02 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::setPositionX(float x)
|
2013-01-21 16:26:02 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
setPosition(Vec2(x, _position.y));
|
2013-01-21 16:26:02 +08:00
|
|
|
}
|
|
|
|
|
2014-02-23 11:16:42 +08:00
|
|
|
float Node::getPositionY() const
|
|
|
|
{
|
|
|
|
return _position.y;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::setPositionY(float y)
|
2013-01-21 16:26:02 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
setPosition(Vec2(_position.x, y));
|
2013-01-21 16:26:02 +08:00
|
|
|
}
|
|
|
|
|
2014-02-23 11:16:42 +08:00
|
|
|
float Node::getPositionZ() const
|
|
|
|
{
|
|
|
|
return _positionZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::setPositionZ(float positionZ)
|
|
|
|
{
|
2014-02-27 15:12:57 +08:00
|
|
|
if (_positionZ == positionZ)
|
|
|
|
return;
|
|
|
|
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2014-02-23 11:16:42 +08:00
|
|
|
|
|
|
|
_positionZ = positionZ;
|
|
|
|
|
|
|
|
// XXX BUG
|
|
|
|
// Global Z Order should based on the modelViewTransform
|
|
|
|
setGlobalZOrder(positionZ);
|
|
|
|
}
|
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
/// position getter
|
|
|
|
const Vec2& Node::getNormalizedPosition() const
|
|
|
|
{
|
|
|
|
return _normalizedPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// position setter
|
|
|
|
void Node::setNormalizedPosition(const Vec2& position)
|
|
|
|
{
|
|
|
|
if (_normalizedPosition.equals(position))
|
|
|
|
return;
|
|
|
|
|
|
|
|
_normalizedPosition = position;
|
|
|
|
_usingNormalizedPosition = true;
|
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
|
|
|
}
|
|
|
|
|
2013-12-12 12:07:20 +08:00
|
|
|
ssize_t Node::getChildrenCount() const
|
2012-02-02 10:39:19 +08:00
|
|
|
{
|
2013-12-05 10:35:10 +08:00
|
|
|
return _children.size();
|
2012-02-02 10:39:19 +08:00
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// isVisible getter
|
2013-07-04 08:22:15 +08:00
|
|
|
bool Node::isVisible() const
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _visible;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// isVisible setter
|
2014-05-28 17:41:34 +08:00
|
|
|
void Node::setVisible(bool visible)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2014-05-28 17:41:34 +08:00
|
|
|
if(visible != _visible)
|
2014-03-07 10:03:34 +08:00
|
|
|
{
|
2014-05-28 17:41:34 +08:00
|
|
|
_visible = visible;
|
2014-03-07 10:03:34 +08:00
|
|
|
if(_visible) _transformUpdated = _transformDirty = _inverseDirty = true;
|
|
|
|
}
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
const Vec2& Node::getAnchorPointInPoints() const
|
2012-03-14 14:55:17 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _anchorPointInPoints;
|
2012-03-14 14:55:17 +08:00
|
|
|
}
|
2010-07-12 17:56:06 +08:00
|
|
|
|
|
|
|
/// anchorPoint getter
|
2014-05-15 01:07:09 +08:00
|
|
|
const Vec2& Node::getAnchorPoint() const
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _anchorPoint;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void Node::setAnchorPoint(const Vec2& point)
|
2010-07-08 10:26:58 +08:00
|
|
|
{
|
2014-02-28 15:31:25 +08:00
|
|
|
#if CC_USE_PHYSICS
|
2014-05-15 01:07:09 +08:00
|
|
|
if (_physicsBody != nullptr && !point.equals(Vec2::ANCHOR_MIDDLE))
|
2014-02-28 15:31:25 +08:00
|
|
|
{
|
|
|
|
CCLOG("Node warning: This node has a physics body, the anchor must be in the middle, you cann't change this to other value.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if( ! point.equals(_anchorPoint))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_anchorPoint = point;
|
2014-05-15 01:07:09 +08:00
|
|
|
_anchorPointInPoints = Vec2(_contentSize.width * _anchorPoint.x, _contentSize.height * _anchorPoint.y );
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2010-07-12 17:56:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// contentSize getter
|
2013-06-20 14:13:12 +08:00
|
|
|
const Size& Node::getContentSize() const
|
2010-07-12 17:56:06 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _contentSize;
|
2010-07-12 17:56:06 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::setContentSize(const Size & size)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if ( ! size.equals(_contentSize))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_contentSize = size;
|
2011-01-04 17:46:23 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
_anchorPointInPoints = Vec2(_contentSize.width * _anchorPoint.x, _contentSize.height * _anchorPoint.y );
|
2014-05-31 07:42:05 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = _contentSizeDirty = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
2011-01-31 06:59:03 +08:00
|
|
|
// isRunning getter
|
2013-07-04 08:22:15 +08:00
|
|
|
bool Node::isRunning() const
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _running;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// parent setter
|
2014-05-28 17:41:34 +08:00
|
|
|
void Node::setParent(Node * parent)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2014-05-28 17:41:34 +08:00
|
|
|
_parent = parent;
|
2014-06-07 16:25:20 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// isRelativeAnchorPoint getter
|
2013-07-04 08:22:15 +08:00
|
|
|
bool Node::isIgnoreAnchorPointForPosition() const
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _ignoreAnchorPointForPosition;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
2010-07-12 17:56:06 +08:00
|
|
|
/// isRelativeAnchorPoint setter
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::ignoreAnchorPointForPosition(bool newValue)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (newValue != _ignoreAnchorPointForPosition)
|
2012-06-08 14:17:39 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_ignoreAnchorPointForPosition = newValue;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2012-06-08 14:17:39 +08:00
|
|
|
}
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// tag getter
|
2013-06-20 14:13:12 +08:00
|
|
|
int Node::getTag() const
|
2010-12-18 16:12:59 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _tag;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// tag setter
|
2014-05-28 17:41:34 +08:00
|
|
|
void Node::setTag(int tag)
|
2010-12-18 16:12:59 +08:00
|
|
|
{
|
2014-05-28 17:41:34 +08:00
|
|
|
_tag = tag ;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
2014-06-11 16:57:43 +08:00
|
|
|
std::string Node::getName() const
|
|
|
|
{
|
|
|
|
return _name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::setName(const std::string& name)
|
|
|
|
{
|
|
|
|
_name = name;
|
|
|
|
std::hash<std::string> h;
|
|
|
|
_hashOfName = h(name);
|
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// userData setter
|
2014-05-28 17:41:34 +08:00
|
|
|
void Node::setUserData(void *userData)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2014-05-28 17:41:34 +08:00
|
|
|
_userData = userData;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
2010-12-18 16:12:59 +08:00
|
|
|
|
2013-07-20 13:01:27 +08:00
|
|
|
int Node::getOrderOfArrival() const
|
2012-11-14 18:05:15 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _orderOfArrival;
|
2012-11-14 18:05:15 +08:00
|
|
|
}
|
|
|
|
|
2013-07-20 13:01:27 +08:00
|
|
|
void Node::setOrderOfArrival(int orderOfArrival)
|
2012-11-14 18:05:15 +08:00
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(orderOfArrival >=0, "Invalid orderOfArrival");
|
|
|
|
_orderOfArrival = orderOfArrival;
|
2012-11-14 18:05:15 +08:00
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
void Node::setUserObject(Ref *userObject)
|
2012-11-14 18:05:15 +08:00
|
|
|
{
|
2014-05-28 17:41:34 +08:00
|
|
|
CC_SAFE_RETAIN(userObject);
|
2013-06-20 22:51:54 +08:00
|
|
|
CC_SAFE_RELEASE(_userObject);
|
2014-05-28 17:41:34 +08:00
|
|
|
_userObject = userObject;
|
2012-11-14 18:05:15 +08:00
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
GLProgramState* Node::getGLProgramState() const
|
2014-05-09 06:43:12 +08:00
|
|
|
{
|
|
|
|
return _glProgramState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::setGLProgramState(cocos2d::GLProgramState *glProgramState)
|
|
|
|
{
|
|
|
|
if(glProgramState != _glProgramState) {
|
|
|
|
CC_SAFE_RELEASE(_glProgramState);
|
|
|
|
_glProgramState = glProgramState;
|
|
|
|
CC_SAFE_RETAIN(_glProgramState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::setGLProgram(GLProgram *glProgram)
|
|
|
|
{
|
2014-05-09 12:54:49 +08:00
|
|
|
if (_glProgramState == nullptr || (_glProgramState && _glProgramState->getGLProgram() != glProgram))
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE(_glProgramState);
|
2014-05-14 09:12:58 +08:00
|
|
|
_glProgramState = GLProgramState::getOrCreateWithGLProgram(glProgram);
|
2014-05-09 06:43:12 +08:00
|
|
|
_glProgramState->retain();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
GLProgram * Node::getGLProgram() const
|
2012-11-14 18:05:15 +08:00
|
|
|
{
|
2014-05-09 06:43:12 +08:00
|
|
|
return _glProgramState ? _glProgramState->getGLProgram() : nullptr;
|
2012-11-14 18:05:15 +08:00
|
|
|
}
|
2010-12-18 16:12:59 +08:00
|
|
|
|
2014-06-17 11:43:03 +08:00
|
|
|
Scene* Node::getScene() const
|
2013-12-22 04:28:49 +08:00
|
|
|
{
|
|
|
|
if(!_parent)
|
|
|
|
return nullptr;
|
2014-02-27 15:12:57 +08:00
|
|
|
|
2013-12-22 04:28:49 +08:00
|
|
|
return _parent->getScene();
|
|
|
|
}
|
|
|
|
|
2013-07-17 09:16:04 +08:00
|
|
|
Rect Node::getBoundingBox() const
|
2010-07-20 14:29:18 +08:00
|
|
|
{
|
2013-07-12 14:30:26 +08:00
|
|
|
Rect rect = Rect(0, 0, _contentSize.width, _contentSize.height);
|
2013-12-10 09:32:51 +08:00
|
|
|
return RectApplyAffineTransform(rect, getNodeToParentAffineTransform());
|
2010-07-20 14:29:18 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
Node * Node::create()
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
Node * ret = new Node();
|
|
|
|
if (ret && ret->init())
|
2013-02-27 09:38:30 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
ret->autorelease();
|
2013-02-27 09:38:30 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
CC_SAFE_DELETE(ret);
|
2013-02-27 09:38:30 +08:00
|
|
|
}
|
2013-12-18 17:47:20 +08:00
|
|
|
return ret;
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::cleanup()
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// actions
|
|
|
|
this->stopAllActions();
|
2012-10-23 01:48:22 +08:00
|
|
|
this->unscheduleAllSelectors();
|
|
|
|
|
2014-02-20 16:40:46 +08:00
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
2013-07-22 17:12:53 +08:00
|
|
|
if ( _scriptType != kScriptTypeNone)
|
2013-07-02 15:23:51 +08:00
|
|
|
{
|
|
|
|
int action = kNodeOnCleanup;
|
2013-07-22 17:12:53 +08:00
|
|
|
BasicScriptData data(this,(void*)&action);
|
2013-07-04 15:44:42 +08:00
|
|
|
ScriptEvent scriptEvent(kNodeEvent,(void*)&data);
|
2013-07-22 17:24:54 +08:00
|
|
|
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent);
|
2013-07-02 15:23:51 +08:00
|
|
|
}
|
2014-02-20 16:40:46 +08:00
|
|
|
#endif // #if CC_ENABLE_SCRIPT_BINDING
|
2012-10-23 01:48:22 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// timers
|
2013-12-19 08:56:59 +08:00
|
|
|
for( const auto &child: _children)
|
2013-11-28 16:02:03 +08:00
|
|
|
child->cleanup();
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
2010-07-14 10:36:26 +08:00
|
|
|
|
2010-07-15 11:39:05 +08:00
|
|
|
|
2013-12-13 06:30:22 +08:00
|
|
|
std::string Node::getDescription() const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-12-12 09:47:35 +08:00
|
|
|
return StringUtils::format("<Node | Tag = %d", _tag);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-11-28 17:57:13 +08:00
|
|
|
// lazy allocs
|
2014-05-28 17:41:34 +08:00
|
|
|
void Node::childrenAlloc()
|
2013-11-28 17:57:13 +08:00
|
|
|
{
|
2013-12-05 10:35:10 +08:00
|
|
|
_children.reserve(4);
|
2013-11-28 17:57:13 +08:00
|
|
|
}
|
|
|
|
|
2014-05-17 15:40:36 +08:00
|
|
|
Node* Node::getChildByTag(int tag) const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
CCASSERT( tag != Node::INVALID_TAG, "Invalid tag");
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-11-28 16:02:03 +08:00
|
|
|
for (auto& child : _children)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
if(child && child->_tag == tag)
|
2013-11-28 16:02:03 +08:00
|
|
|
return child;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-11-28 16:02:03 +08:00
|
|
|
return nullptr;
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2014-06-11 16:57:43 +08:00
|
|
|
Node* Node::getChildByName(const std::string& name) const
|
|
|
|
{
|
2014-06-17 11:43:03 +08:00
|
|
|
CCASSERT(name.length() != 0, "Invalid name");
|
2014-06-11 16:57:43 +08:00
|
|
|
|
|
|
|
std::hash<std::string> h;
|
|
|
|
size_t hash = h(name);
|
|
|
|
|
2014-06-12 10:41:08 +08:00
|
|
|
for (const auto& child : _children)
|
2014-06-11 16:57:43 +08:00
|
|
|
{
|
|
|
|
// Different strings may have the same hash code, but can use it to compare first for speed
|
|
|
|
if(child->_hashOfName == hash && child->_name.compare(name) == 0)
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-06-17 11:43:03 +08:00
|
|
|
void Node::enumerateChildren(const std::string &name, std::function<bool (Node *)> callback) const
|
2014-06-12 10:41:08 +08:00
|
|
|
{
|
2014-06-17 11:43:03 +08:00
|
|
|
CCASSERT(name.length() != 0, "Invalid name");
|
|
|
|
CCASSERT(callback != nullptr, "Invalid callback function");
|
2014-06-12 10:41:08 +08:00
|
|
|
|
2014-06-17 11:43:03 +08:00
|
|
|
size_t length = name.length();
|
2014-06-12 10:41:08 +08:00
|
|
|
|
2014-06-17 11:43:03 +08:00
|
|
|
size_t subStrStartPos = 0; // sub string start index
|
|
|
|
size_t subStrlength = length; // sub string length
|
|
|
|
|
2014-07-10 11:07:39 +08:00
|
|
|
// Starts with '//'?
|
|
|
|
bool searchRecursively = false;
|
|
|
|
if (length > 2 && name[0] == '/' && name[1] == '/')
|
2014-06-12 10:41:08 +08:00
|
|
|
{
|
2014-07-10 11:07:39 +08:00
|
|
|
searchRecursively = true;
|
|
|
|
subStrStartPos = 2;
|
|
|
|
subStrlength -= 2;
|
2014-06-17 11:43:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// End with '/..'?
|
2014-07-02 17:07:36 +08:00
|
|
|
bool searchFromParent = false;
|
|
|
|
if (length > 3 &&
|
|
|
|
name[length-3] == '/' &&
|
|
|
|
name[length-2] == '.' &&
|
|
|
|
name[length-1] == '.')
|
|
|
|
{
|
|
|
|
searchFromParent = true;
|
|
|
|
subStrlength -= 3;
|
|
|
|
}
|
|
|
|
|
2014-07-10 11:07:39 +08:00
|
|
|
// Remove '//', '/..' if exist
|
2014-06-17 11:43:03 +08:00
|
|
|
std::string newName = name.substr(subStrStartPos, subStrlength);
|
2014-07-02 17:07:36 +08:00
|
|
|
|
|
|
|
if (searchFromParent)
|
|
|
|
{
|
|
|
|
newName.insert(0, "[[:alnum:]]+/");
|
|
|
|
}
|
2014-06-17 11:43:03 +08:00
|
|
|
|
2014-07-10 11:07:39 +08:00
|
|
|
|
|
|
|
if (searchRecursively)
|
2014-06-17 11:43:03 +08:00
|
|
|
{
|
|
|
|
// name is '//xxx'
|
2014-07-10 11:07:39 +08:00
|
|
|
doEnumerateRecursive(this, newName, callback);
|
2014-06-17 11:43:03 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// name is xxx
|
|
|
|
doEnumerate(newName, callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Node::doEnumerateRecursive(const Node* node, const std::string &name, std::function<bool (Node *)> callback) const
|
|
|
|
{
|
|
|
|
bool ret =false;
|
|
|
|
|
|
|
|
if (node->doEnumerate(name, callback))
|
|
|
|
{
|
|
|
|
// search itself
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// search its children
|
|
|
|
for (const auto& child : node->getChildren())
|
2014-06-12 10:41:08 +08:00
|
|
|
{
|
2014-06-17 11:43:03 +08:00
|
|
|
if (doEnumerateRecursive(child, name, callback))
|
|
|
|
{
|
|
|
|
ret = true;
|
2014-06-12 10:41:08 +08:00
|
|
|
break;
|
2014-06-17 11:43:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Node::doEnumerate(std::string name, std::function<bool (Node *)> callback) const
|
|
|
|
{
|
|
|
|
// name may be xxx/yyy, should find its parent
|
|
|
|
size_t pos = name.find('/');
|
|
|
|
std::string searchName = name;
|
|
|
|
bool needRecursive = false;
|
|
|
|
if (pos != name.npos)
|
|
|
|
{
|
|
|
|
searchName = name.substr(0, pos);
|
|
|
|
name.erase(0, pos+1);
|
|
|
|
needRecursive = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ret = false;
|
|
|
|
for (const auto& child : _children)
|
|
|
|
{
|
2014-07-02 17:07:36 +08:00
|
|
|
if (std::regex_match(child->_name, std::regex(searchName)))
|
2014-06-17 11:43:03 +08:00
|
|
|
{
|
|
|
|
if (!needRecursive)
|
|
|
|
{
|
|
|
|
// terminate enumeration if callback return true
|
|
|
|
if (callback(child))
|
|
|
|
{
|
|
|
|
ret = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = child->doEnumerate(name, callback);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
}
|
2014-06-12 10:41:08 +08:00
|
|
|
}
|
|
|
|
}
|
2014-06-17 11:43:03 +08:00
|
|
|
|
|
|
|
return ret;
|
2014-06-12 10:41:08 +08:00
|
|
|
}
|
|
|
|
|
2010-07-09 18:24:08 +08:00
|
|
|
/* "add" logic MUST only be on this method
|
2012-09-17 15:02:24 +08:00
|
|
|
* If a class want's to extend the 'addChild' behavior it only needs
|
2010-07-09 18:24:08 +08:00
|
|
|
* to override this method
|
|
|
|
*/
|
2014-06-25 11:27:48 +08:00
|
|
|
void Node::addChild(Node *child, int localZOrder, int tag)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
CCASSERT( child != nullptr, "Argument must be non-nil");
|
|
|
|
CCASSERT( child->_parent == nullptr, "child already added. It can't be added again");
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2014-06-25 11:27:48 +08:00
|
|
|
addChildHelper(child, localZOrder, tag, "", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::addChild(Node* child, int localZOrder, const std::string &name)
|
|
|
|
{
|
|
|
|
CCASSERT(child != nullptr, "Argument must be non-nil");
|
|
|
|
CCASSERT(child->_parent == nullptr, "child already added. It can't be added again");
|
|
|
|
|
|
|
|
addChildHelper(child, localZOrder, INVALID_TAG, name, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::addChildHelper(Node* child, int localZOrder, int tag, const std::string &name, bool setTag)
|
|
|
|
{
|
2013-11-28 18:23:06 +08:00
|
|
|
if (_children.empty())
|
2013-11-28 17:57:13 +08:00
|
|
|
{
|
|
|
|
this->childrenAlloc();
|
|
|
|
}
|
2014-06-25 11:27:48 +08:00
|
|
|
|
|
|
|
this->insertChild(child, localZOrder);
|
|
|
|
|
|
|
|
if (setTag)
|
|
|
|
child->setTag(tag);
|
|
|
|
else
|
|
|
|
child->setName(name);
|
|
|
|
|
2014-04-15 03:21:18 +08:00
|
|
|
child->setParent(this);
|
|
|
|
child->setOrderOfArrival(s_globalOrderOfArrival++);
|
2013-10-28 16:17:19 +08:00
|
|
|
|
2013-12-26 23:55:05 +08:00
|
|
|
#if CC_USE_PHYSICS
|
2014-04-15 03:21:18 +08:00
|
|
|
// Recursive add children with which have physics body.
|
2014-06-27 17:30:21 +08:00
|
|
|
Scene* scene = this->getScene();
|
|
|
|
if (scene != nullptr && scene->getPhysicsWorld() != nullptr)
|
2013-10-28 16:17:19 +08:00
|
|
|
{
|
2014-06-27 17:30:21 +08:00
|
|
|
child->updatePhysicsBodyTransform(scene);
|
|
|
|
scene->addChildToPhysicsWorld(child);
|
2013-10-28 16:17:19 +08:00
|
|
|
}
|
|
|
|
#endif
|
2014-06-25 11:27:48 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if( _running )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
child->onEnter();
|
2013-05-27 20:46:15 +08:00
|
|
|
// prevent onEnterTransitionDidFinish to be called twice when a node is added in onEnter
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_isTransitionFinished) {
|
2013-05-27 20:46:15 +08:00
|
|
|
child->onEnterTransitionDidFinish();
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-12-06 18:07:16 +08:00
|
|
|
|
|
|
|
if (_cascadeColorEnabled)
|
|
|
|
{
|
|
|
|
updateCascadeColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_cascadeOpacityEnabled)
|
|
|
|
{
|
|
|
|
updateCascadeOpacity();
|
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::addChild(Node *child, int zOrder)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
CCASSERT( child != nullptr, "Argument must be non-nil");
|
2014-06-25 11:27:48 +08:00
|
|
|
this->addChild(child, zOrder, child->_name);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::addChild(Node *child)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
CCASSERT( child != nullptr, "Argument must be non-nil");
|
2014-06-25 11:27:48 +08:00
|
|
|
this->addChild(child, child->_localZOrder, child->_name);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::removeFromParent()
|
2012-11-09 12:08:18 +08:00
|
|
|
{
|
|
|
|
this->removeFromParentAndCleanup(true);
|
2012-11-05 18:41:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::removeFromParentAndCleanup(bool cleanup)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
if (_parent != nullptr)
|
2012-05-02 12:04:27 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_parent->removeChild(this,cleanup);
|
2012-05-02 12:04:27 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* "remove" logic MUST only be on this method
|
|
|
|
* If a class want's to extend the 'removeChild' behavior it only needs
|
|
|
|
* to override this method
|
|
|
|
*/
|
2013-07-19 14:57:54 +08:00
|
|
|
void Node::removeChild(Node* child, bool cleanup /* = true */)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// explicit nil handling
|
2013-11-28 18:23:06 +08:00
|
|
|
if (_children.empty())
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-12-12 12:07:20 +08:00
|
|
|
ssize_t index = _children.getIndex(child);
|
2013-08-27 09:04:51 +08:00
|
|
|
if( index != CC_INVALID_INDEX )
|
|
|
|
this->detachChild( child, index, cleanup );
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-07-19 14:57:54 +08:00
|
|
|
void Node::removeChildByTag(int tag, bool cleanup/* = true */)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-08-29 03:42:25 +08:00
|
|
|
CCASSERT( tag != Node::INVALID_TAG, "Invalid tag");
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Node *child = this->getChildByTag(tag);
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
if (child == nullptr)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-04-28 03:15:00 +08:00
|
|
|
CCLOG("cocos2d: removeChildByTag(tag = %d): child not found!", tag);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->removeChild(child, cleanup);
|
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2014-06-25 11:27:48 +08:00
|
|
|
void Node::removeChildByName(const std::string &name, bool cleanup)
|
|
|
|
{
|
|
|
|
CCASSERT(name.length() != 0, "Invalid name");
|
|
|
|
|
|
|
|
Node *child = this->getChildByName(name);
|
|
|
|
|
|
|
|
if (child == nullptr)
|
|
|
|
{
|
|
|
|
CCLOG("cocos2d: removeChildByName(name = %s): child not found!", name.c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->removeChild(child, cleanup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::removeAllChildren()
|
2012-11-05 18:41:52 +08:00
|
|
|
{
|
|
|
|
this->removeAllChildrenWithCleanup(true);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::removeAllChildrenWithCleanup(bool cleanup)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// not using detachChild improves speed here
|
2013-12-19 08:56:59 +08:00
|
|
|
for (auto& child : _children)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-19 08:56:59 +08:00
|
|
|
// IMPORTANT:
|
|
|
|
// -1st do onExit
|
|
|
|
// -2nd cleanup
|
|
|
|
if(_running)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-19 08:56:59 +08:00
|
|
|
child->onExitTransitionDidStart();
|
|
|
|
child->onExit();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-12-19 08:56:59 +08:00
|
|
|
|
2014-03-08 17:42:35 +08:00
|
|
|
#if CC_USE_PHYSICS
|
|
|
|
if (child->_physicsBody != nullptr)
|
|
|
|
{
|
|
|
|
child->_physicsBody->removeFromWorld();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-12-19 08:56:59 +08:00
|
|
|
if (cleanup)
|
|
|
|
{
|
|
|
|
child->cleanup();
|
|
|
|
}
|
|
|
|
// set parent nil at the end
|
|
|
|
child->setParent(nullptr);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 08:56:59 +08:00
|
|
|
_children.clear();
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-12-12 12:07:20 +08:00
|
|
|
void Node::detachChild(Node *child, ssize_t childIndex, bool doCleanup)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// IMPORTANT:
|
|
|
|
// -1st do onExit
|
|
|
|
// -2nd cleanup
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_running)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
child->onExitTransitionDidStart();
|
|
|
|
child->onExit();
|
|
|
|
}
|
2013-10-28 11:08:41 +08:00
|
|
|
|
2013-12-26 23:55:05 +08:00
|
|
|
#if CC_USE_PHYSICS
|
2013-10-28 11:08:41 +08:00
|
|
|
if (child->_physicsBody != nullptr)
|
|
|
|
{
|
|
|
|
child->_physicsBody->removeFromWorld();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// If you don't do cleanup, the child's actions will not get removed and the
|
|
|
|
// its scheduledSelectors_ dict will not get released!
|
|
|
|
if (doCleanup)
|
|
|
|
{
|
|
|
|
child->cleanup();
|
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// set parent nil at the end
|
2013-11-28 16:02:03 +08:00
|
|
|
child->setParent(nullptr);
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-12-11 17:53:45 +08:00
|
|
|
_children.erase(childIndex);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// helper used by reorderChild & add
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::insertChild(Node* child, int z)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-05-13 14:28:20 +08:00
|
|
|
_transformUpdated = true;
|
2013-06-15 14:03:30 +08:00
|
|
|
_reorderChildDirty = true;
|
2013-12-05 10:35:10 +08:00
|
|
|
_children.pushBack(child);
|
2014-01-19 03:35:27 +08:00
|
|
|
child->_setLocalZOrder(z);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::reorderChild(Node *child, int zOrder)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
CCASSERT( child != nullptr, "Child must be non-nil");
|
2013-06-15 14:03:30 +08:00
|
|
|
_reorderChildDirty = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
child->setOrderOfArrival(s_globalOrderOfArrival++);
|
2014-01-19 03:35:27 +08:00
|
|
|
child->_setLocalZOrder(zOrder);
|
2012-03-14 14:55:17 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::sortAllChildren()
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2013-08-25 01:56:07 +08:00
|
|
|
if( _reorderChildDirty ) {
|
2013-11-28 16:02:03 +08:00
|
|
|
std::sort( std::begin(_children), std::end(_children), nodeComparisonLess );
|
2013-08-25 01:56:07 +08:00
|
|
|
_reorderChildDirty = false;
|
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2014-02-28 13:43:54 +08:00
|
|
|
void Node::draw()
|
|
|
|
{
|
|
|
|
auto renderer = Director::getInstance()->getRenderer();
|
|
|
|
draw(renderer, _modelViewTransform, true);
|
|
|
|
}
|
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
void Node::draw(Renderer* renderer, const Mat4 &transform, uint32_t flags)
|
2014-02-28 13:43:54 +08:00
|
|
|
{
|
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::visit()
|
2014-02-28 13:43:54 +08:00
|
|
|
{
|
|
|
|
auto renderer = Director::getInstance()->getRenderer();
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 parentTransform = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2014-04-04 18:13:10 +08:00
|
|
|
visit(renderer, parentTransform, true);
|
2014-02-28 13:43:54 +08:00
|
|
|
}
|
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
uint32_t Node::processParentFlags(const Mat4& parentTransform, uint32_t parentFlags)
|
|
|
|
{
|
|
|
|
uint32_t flags = parentFlags;
|
2014-05-31 12:50:39 +08:00
|
|
|
flags |= (_transformUpdated ? FLAGS_TRANSFORM_DIRTY : 0);
|
|
|
|
flags |= (_contentSizeDirty ? FLAGS_CONTENT_SIZE_DIRTY : 0);
|
2014-05-31 07:42:05 +08:00
|
|
|
|
2014-05-31 12:50:39 +08:00
|
|
|
if(_usingNormalizedPosition && (flags & FLAGS_CONTENT_SIZE_DIRTY)) {
|
2014-05-31 07:42:05 +08:00
|
|
|
CCASSERT(_parent, "setNormalizedPosition() doesn't work with orphan nodes");
|
|
|
|
auto s = _parent->getContentSize();
|
|
|
|
_position.x = _normalizedPosition.x * s.width;
|
|
|
|
_position.y = _normalizedPosition.y * s.height;
|
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
|
|
|
}
|
|
|
|
|
2014-05-31 12:50:39 +08:00
|
|
|
if(flags & FLAGS_DIRTY_MASK)
|
2014-05-31 07:42:05 +08:00
|
|
|
_modelViewTransform = this->transform(parentTransform);
|
|
|
|
|
|
|
|
_transformUpdated = false;
|
|
|
|
_contentSizeDirty = false;
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2014-08-14 10:26:37 +08:00
|
|
|
bool Node::isVisitableByVisitingCamera() const
|
2014-08-13 12:06:51 +08:00
|
|
|
{
|
|
|
|
auto camera = Camera::getVisitingCamera();
|
|
|
|
bool visibleByCamera = camera ? (unsigned short)camera->getCameraFlag() & _cameraMask : true;
|
|
|
|
return visibleByCamera;
|
|
|
|
}
|
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
void Node::visit(Renderer* renderer, const Mat4 &parentTransform, uint32_t parentFlags)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// quick return if not visible. children won't be drawn.
|
2013-06-15 14:03:30 +08:00
|
|
|
if (!_visible)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2010-08-17 14:25:41 +08:00
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
uint32_t flags = processParentFlags(parentTransform, parentFlags);
|
2014-03-01 03:20:53 +08:00
|
|
|
|
|
|
|
// IMPORTANT:
|
2014-05-15 01:07:09 +08:00
|
|
|
// To ease the migration to v3.0, we still support the Mat4 stack,
|
2014-03-01 03:20:53 +08:00
|
|
|
// but it is deprecated and your code should not rely on it
|
2014-04-03 10:33:59 +08:00
|
|
|
Director* director = Director::getInstance();
|
|
|
|
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
|
|
|
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
|
2014-08-07 15:23:31 +08:00
|
|
|
|
2014-08-14 10:26:37 +08:00
|
|
|
bool visibleByCamera = isVisitableByVisitingCamera();
|
2014-02-28 13:43:54 +08:00
|
|
|
|
2013-12-05 17:19:01 +08:00
|
|
|
int i = 0;
|
2010-08-04 10:36:37 +08:00
|
|
|
|
2013-11-28 18:23:06 +08:00
|
|
|
if(!_children.empty())
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
sortAllChildren();
|
|
|
|
// draw children zOrder < 0
|
2013-12-05 10:35:10 +08:00
|
|
|
for( ; i < _children.size(); i++ )
|
2011-04-21 14:46:15 +08:00
|
|
|
{
|
2013-12-05 10:35:10 +08:00
|
|
|
auto node = _children.at(i);
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2014-01-19 03:35:27 +08:00
|
|
|
if ( node && node->_localZOrder < 0 )
|
2014-05-31 07:42:05 +08:00
|
|
|
node->visit(renderer, _modelViewTransform, flags);
|
2012-04-19 14:35:52 +08:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// self draw
|
2014-08-07 15:23:31 +08:00
|
|
|
if (visibleByCamera)
|
|
|
|
this->draw(renderer, _modelViewTransform, flags);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-19 10:33:04 +08:00
|
|
|
for(auto it=_children.cbegin()+i; it != _children.cend(); ++it)
|
2014-05-31 07:42:05 +08:00
|
|
|
(*it)->visit(renderer, _modelViewTransform, flags);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2014-08-13 12:06:51 +08:00
|
|
|
else if (visibleByCamera)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-08-13 12:06:51 +08:00
|
|
|
this->draw(renderer, _modelViewTransform, flags);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-04-03 10:33:59 +08:00
|
|
|
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2014-06-19 15:09:27 +08:00
|
|
|
|
|
|
|
// FIX ME: Why need to set _orderOfArrival to 0??
|
|
|
|
// Please refer to https://github.com/cocos2d/cocos2d-x/pull/6920
|
|
|
|
// reset for next frame
|
|
|
|
// _orderOfArrival = 0;
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 Node::transform(const Mat4& parentTransform)
|
2013-10-18 15:34:13 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 ret = this->getNodeToParentTransform();
|
2014-04-08 23:05:33 +08:00
|
|
|
ret = parentTransform * ret;
|
2014-03-01 03:20:53 +08:00
|
|
|
return ret;
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2014-03-08 11:51:10 +08:00
|
|
|
void Node::onEnter()
|
|
|
|
{
|
2014-07-04 01:16:10 +08:00
|
|
|
if (_onEnterCallback)
|
|
|
|
_onEnterCallback();
|
2014-07-03 23:42:06 +08:00
|
|
|
|
2014-03-08 11:51:10 +08:00
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
|
|
|
if (_scriptType == kScriptTypeJavascript)
|
|
|
|
{
|
2014-06-18 11:51:52 +08:00
|
|
|
if (ScriptEngineManager::sendNodeEventToJS(this, kNodeOnEnter))
|
2014-03-08 11:51:10 +08:00
|
|
|
return;
|
2013-07-02 15:23:51 +08:00
|
|
|
}
|
2014-02-20 16:40:46 +08:00
|
|
|
#endif
|
2013-12-30 11:10:02 +08:00
|
|
|
|
2014-03-08 11:51:10 +08:00
|
|
|
_isTransitionFinished = false;
|
|
|
|
|
2013-12-30 11:10:02 +08:00
|
|
|
for( const auto &child: _children)
|
|
|
|
child->onEnter();
|
2014-03-08 11:51:10 +08:00
|
|
|
|
2013-12-30 11:10:02 +08:00
|
|
|
this->resume();
|
|
|
|
|
|
|
|
_running = true;
|
2014-03-08 11:51:10 +08:00
|
|
|
|
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
|
|
|
if (_scriptType == kScriptTypeLua)
|
|
|
|
{
|
2014-06-18 11:51:52 +08:00
|
|
|
ScriptEngineManager::sendNodeEventToLua(this, kNodeOnEnter);
|
2014-03-08 11:51:10 +08:00
|
|
|
}
|
|
|
|
#endif
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::onEnterTransitionDidFinish()
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-07-04 01:16:10 +08:00
|
|
|
if (_onEnterTransitionDidFinishCallback)
|
|
|
|
_onEnterTransitionDidFinishCallback();
|
2014-07-03 23:42:06 +08:00
|
|
|
|
2014-02-20 16:40:46 +08:00
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
2014-03-08 11:51:10 +08:00
|
|
|
if (_scriptType == kScriptTypeJavascript)
|
2013-07-02 15:23:51 +08:00
|
|
|
{
|
2014-06-18 11:51:52 +08:00
|
|
|
if (ScriptEngineManager::sendNodeEventToJS(this, kNodeOnEnterTransitionDidFinish))
|
2014-03-08 11:51:10 +08:00
|
|
|
return;
|
2013-07-02 15:23:51 +08:00
|
|
|
}
|
2014-02-20 16:40:46 +08:00
|
|
|
#endif
|
2014-03-08 11:51:10 +08:00
|
|
|
|
|
|
|
_isTransitionFinished = true;
|
2013-12-30 11:10:02 +08:00
|
|
|
for( const auto &child: _children)
|
|
|
|
child->onEnterTransitionDidFinish();
|
2014-03-08 11:51:10 +08:00
|
|
|
|
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
|
|
|
if (_scriptType == kScriptTypeLua)
|
|
|
|
{
|
2014-06-18 11:51:52 +08:00
|
|
|
ScriptEngineManager::sendNodeEventToLua(this, kNodeOnEnterTransitionDidFinish);
|
2014-03-08 11:51:10 +08:00
|
|
|
}
|
|
|
|
#endif
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::onExitTransitionDidStart()
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2014-07-04 01:16:10 +08:00
|
|
|
if (_onExitTransitionDidStartCallback)
|
|
|
|
_onExitTransitionDidStartCallback();
|
2014-07-03 23:42:06 +08:00
|
|
|
|
2014-03-08 11:51:10 +08:00
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
|
|
|
if (_scriptType == kScriptTypeJavascript)
|
|
|
|
{
|
2014-06-18 11:51:52 +08:00
|
|
|
if (ScriptEngineManager::sendNodeEventToJS(this, kNodeOnExitTransitionDidStart))
|
2014-03-08 11:51:10 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-12-19 08:56:59 +08:00
|
|
|
for( const auto &child: _children)
|
2013-11-28 16:02:03 +08:00
|
|
|
child->onExitTransitionDidStart();
|
2014-03-08 11:51:10 +08:00
|
|
|
|
2014-02-20 16:40:46 +08:00
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
2014-03-08 11:51:10 +08:00
|
|
|
if (_scriptType == kScriptTypeLua)
|
2013-07-02 15:23:51 +08:00
|
|
|
{
|
2014-06-18 11:51:52 +08:00
|
|
|
ScriptEngineManager::sendNodeEventToLua(this, kNodeOnExitTransitionDidStart);
|
2012-08-31 17:55:45 +08:00
|
|
|
}
|
2014-02-20 16:40:46 +08:00
|
|
|
#endif
|
2012-03-14 14:55:17 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::onExit()
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-07-04 01:16:10 +08:00
|
|
|
if (_onExitCallback)
|
|
|
|
_onExitCallback();
|
2014-07-03 23:42:06 +08:00
|
|
|
|
2014-03-08 11:51:10 +08:00
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
|
|
|
if (_scriptType == kScriptTypeJavascript)
|
|
|
|
{
|
2014-06-18 11:51:52 +08:00
|
|
|
if (ScriptEngineManager::sendNodeEventToJS(this, kNodeOnExit))
|
2014-03-08 11:51:10 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-10-26 15:04:01 +08:00
|
|
|
this->pause();
|
2014-03-08 11:51:10 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_running = false;
|
2014-03-08 11:51:10 +08:00
|
|
|
|
2013-12-30 11:10:02 +08:00
|
|
|
for( const auto &child: _children)
|
|
|
|
child->onExit();
|
|
|
|
|
2014-02-20 16:40:46 +08:00
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
2014-03-08 11:51:10 +08:00
|
|
|
if (_scriptType == kScriptTypeLua)
|
2013-07-02 15:23:51 +08:00
|
|
|
{
|
2014-06-18 11:51:52 +08:00
|
|
|
ScriptEngineManager::sendNodeEventToLua(this, kNodeOnExit);
|
2013-07-02 15:23:51 +08:00
|
|
|
}
|
2014-02-20 16:40:46 +08:00
|
|
|
#endif
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
2012-02-02 15:58:10 +08:00
|
|
|
|
2013-10-26 15:04:01 +08:00
|
|
|
void Node::setEventDispatcher(EventDispatcher* dispatcher)
|
|
|
|
{
|
|
|
|
if (dispatcher != _eventDispatcher)
|
|
|
|
{
|
2014-03-02 15:54:36 +08:00
|
|
|
_eventDispatcher->removeEventListenersForTarget(this);
|
2013-10-26 15:04:01 +08:00
|
|
|
CC_SAFE_RETAIN(dispatcher);
|
|
|
|
CC_SAFE_RELEASE(_eventDispatcher);
|
|
|
|
_eventDispatcher = dispatcher;
|
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
2012-02-02 15:58:10 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::setActionManager(ActionManager* actionManager)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if( actionManager != _actionManager ) {
|
2012-04-19 14:35:52 +08:00
|
|
|
this->stopAllActions();
|
|
|
|
CC_SAFE_RETAIN(actionManager);
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE(_actionManager);
|
|
|
|
_actionManager = actionManager;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Action * Node::runAction(Action* action)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
CCASSERT( action != nullptr, "Argument must be non-nil");
|
2013-06-15 14:03:30 +08:00
|
|
|
_actionManager->addAction(action, this, !_running);
|
2012-04-19 14:35:52 +08:00
|
|
|
return action;
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::stopAllActions()
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_actionManager->removeAllActionsFromTarget(this);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::stopAction(Action* action)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_actionManager->removeAction(action);
|
2010-08-06 09:46:56 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::stopActionByTag(int tag)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-08-29 03:42:25 +08:00
|
|
|
CCASSERT( tag != Action::INVALID_TAG, "Invalid tag");
|
2013-06-15 14:03:30 +08:00
|
|
|
_actionManager->removeActionByTag(tag, this);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-07-19 07:30:19 +08:00
|
|
|
Action * Node::getActionByTag(int tag)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-08-29 03:42:25 +08:00
|
|
|
CCASSERT( tag != Action::INVALID_TAG, "Invalid tag");
|
2013-06-15 14:03:30 +08:00
|
|
|
return _actionManager->getActionByTag(tag, this);
|
2010-08-06 09:46:56 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-12-12 12:07:20 +08:00
|
|
|
ssize_t Node::getNumberOfRunningActions() const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
return _actionManager->getNumberOfRunningActionsInTarget(this);
|
2012-03-14 14:55:17 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
// Node - Callbacks
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::setScheduler(Scheduler* scheduler)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if( scheduler != _scheduler ) {
|
2012-04-19 14:35:52 +08:00
|
|
|
this->unscheduleAllSelectors();
|
|
|
|
CC_SAFE_RETAIN(scheduler);
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE(_scheduler);
|
|
|
|
_scheduler = scheduler;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2013-06-27 12:05:47 +08:00
|
|
|
bool Node::isScheduled(SEL_SCHEDULE selector)
|
|
|
|
{
|
2014-03-03 11:00:30 +08:00
|
|
|
return _scheduler->isScheduled(selector, this);
|
2013-06-27 12:05:47 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::scheduleUpdate()
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
scheduleUpdateWithPriority(0);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::scheduleUpdateWithPriority(int priority)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-03-03 11:00:30 +08:00
|
|
|
_scheduler->scheduleUpdate(this, priority, !_running);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::scheduleUpdateWithPriorityLua(int nHandler, int priority)
|
2013-01-17 11:20:25 +08:00
|
|
|
{
|
|
|
|
unscheduleUpdate();
|
2014-02-20 16:40:46 +08:00
|
|
|
|
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
2013-06-15 14:03:30 +08:00
|
|
|
_updateScriptHandler = nHandler;
|
2014-02-20 16:40:46 +08:00
|
|
|
#endif
|
2014-03-01 13:30:20 +08:00
|
|
|
|
2014-03-03 11:00:30 +08:00
|
|
|
_scheduler->scheduleUpdate(this, priority, !_running);
|
2013-01-17 11:20:25 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::unscheduleUpdate()
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-02-20 10:53:49 +08:00
|
|
|
_scheduler->unscheduleUpdate(this);
|
2014-02-20 16:40:46 +08:00
|
|
|
|
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_updateScriptHandler)
|
2012-12-10 13:48:27 +08:00
|
|
|
{
|
2013-07-22 17:24:54 +08:00
|
|
|
ScriptEngineManager::getInstance()->getScriptEngine()->removeScriptHandler(_updateScriptHandler);
|
2013-06-15 14:03:30 +08:00
|
|
|
_updateScriptHandler = 0;
|
2012-12-10 13:48:27 +08:00
|
|
|
}
|
2014-02-20 16:40:46 +08:00
|
|
|
#endif
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::schedule(SEL_SCHEDULE selector)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
this->schedule(selector, 0.0f, kRepeatForever, 0.0f);
|
2012-03-14 14:55:17 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::schedule(SEL_SCHEDULE selector, float interval)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
this->schedule(selector, interval, kRepeatForever, 0.0f);
|
2010-07-14 11:52:27 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::schedule(SEL_SCHEDULE selector, float interval, unsigned int repeat, float delay)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT( selector, "Argument must be non-nil");
|
|
|
|
CCASSERT( interval >=0, "Argument must be positive");
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2014-03-03 11:00:30 +08:00
|
|
|
_scheduler->schedule(selector, this, interval , repeat, delay, !_running);
|
2012-03-14 14:55:17 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::scheduleOnce(SEL_SCHEDULE selector, float delay)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
this->schedule(selector, 0.0f, 0, delay);
|
2010-07-14 11:52:27 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::unschedule(SEL_SCHEDULE selector)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-02-20 10:53:49 +08:00
|
|
|
// explicit null handling
|
|
|
|
if (selector == nullptr)
|
2012-04-19 14:35:52 +08:00
|
|
|
return;
|
2014-02-20 10:53:49 +08:00
|
|
|
|
2014-03-03 11:00:30 +08:00
|
|
|
_scheduler->unschedule(selector, this);
|
2010-07-14 11:52:27 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::unscheduleAllSelectors()
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_scheduler->unscheduleAllForTarget(this);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-10-26 15:04:01 +08:00
|
|
|
void Node::resume()
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_scheduler->resumeTarget(this);
|
|
|
|
_actionManager->resumeTarget(this);
|
2014-03-02 15:54:36 +08:00
|
|
|
_eventDispatcher->resumeEventListenersForTarget(this);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2013-10-26 15:04:01 +08:00
|
|
|
void Node::pause()
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_scheduler->pauseTarget(this);
|
|
|
|
_actionManager->pauseTarget(this);
|
2014-03-02 15:54:36 +08:00
|
|
|
_eventDispatcher->pauseEventListenersForTarget(this);
|
2013-10-26 15:04:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Node::resumeSchedulerAndActions()
|
|
|
|
{
|
|
|
|
resume();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::pauseSchedulerAndActions()
|
|
|
|
{
|
|
|
|
pause();
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2012-11-14 18:05:15 +08:00
|
|
|
// override me
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::update(float fDelta)
|
2012-11-14 18:05:15 +08:00
|
|
|
{
|
2014-02-20 16:40:46 +08:00
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
2013-07-02 15:23:51 +08:00
|
|
|
if (0 != _updateScriptHandler)
|
2012-12-10 13:48:27 +08:00
|
|
|
{
|
2013-07-02 15:23:51 +08:00
|
|
|
//only lua use
|
2013-07-04 15:44:42 +08:00
|
|
|
SchedulerScriptData data(_updateScriptHandler,fDelta);
|
2013-07-02 15:23:51 +08:00
|
|
|
ScriptEvent event(kScheduleEvent,&data);
|
2013-07-22 17:24:54 +08:00
|
|
|
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
|
2012-12-10 13:48:27 +08:00
|
|
|
}
|
2014-02-20 16:40:46 +08:00
|
|
|
#endif
|
2013-06-04 17:38:43 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_componentContainer && !_componentContainer->isEmpty())
|
2013-06-04 17:38:43 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_componentContainer->visit(fDelta);
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|
2012-11-14 18:05:15 +08:00
|
|
|
}
|
|
|
|
|
2013-12-10 09:32:51 +08:00
|
|
|
AffineTransform Node::getNodeToParentAffineTransform() const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-12-10 09:32:51 +08:00
|
|
|
AffineTransform ret;
|
2014-04-10 23:12:29 +08:00
|
|
|
GLToCGAffine(getNodeToParentTransform().m, &ret);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-12-10 09:32:51 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
const Mat4& Node::getNodeToParentTransform() const
|
2013-12-10 09:32:51 +08:00
|
|
|
{
|
|
|
|
if (_transformDirty)
|
2012-06-08 14:17:39 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// Translate values
|
2013-06-15 14:03:30 +08:00
|
|
|
float x = _position.x;
|
|
|
|
float y = _position.y;
|
2014-02-23 11:16:42 +08:00
|
|
|
float z = _positionZ;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-12-10 09:32:51 +08:00
|
|
|
if (_ignoreAnchorPointForPosition)
|
2012-06-08 14:17:39 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
x += _anchorPointInPoints.x;
|
|
|
|
y += _anchorPointInPoints.y;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// Rotation values
|
2012-11-14 18:05:15 +08:00
|
|
|
// Change rotation code to handle X and Y
|
|
|
|
// If we skew with the exact same value for both x and y then we're simply just rotating
|
|
|
|
float cx = 1, sx = 0, cy = 1, sy = 0;
|
2014-02-23 11:16:42 +08:00
|
|
|
if (_rotationZ_X || _rotationZ_Y)
|
2012-06-08 14:17:39 +08:00
|
|
|
{
|
2014-02-23 11:16:42 +08:00
|
|
|
float radiansX = -CC_DEGREES_TO_RADIANS(_rotationZ_X);
|
|
|
|
float radiansY = -CC_DEGREES_TO_RADIANS(_rotationZ_Y);
|
2012-11-14 18:05:15 +08:00
|
|
|
cx = cosf(radiansX);
|
|
|
|
sx = sinf(radiansX);
|
|
|
|
cy = cosf(radiansY);
|
|
|
|
sy = sinf(radiansY);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
bool needsSkewMatrix = ( _skewX || _skewY );
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2014-07-02 03:36:53 +08:00
|
|
|
Vec2 anchorPoint;
|
|
|
|
anchorPoint.x = _anchorPointInPoints.x * _scaleX;
|
|
|
|
anchorPoint.y = _anchorPointInPoints.y * _scaleY;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// optimization:
|
|
|
|
// inline anchor point calculation if skew is not needed
|
2012-11-14 18:05:15 +08:00
|
|
|
// Adjusted transform calculation for rotational skew
|
2014-05-15 01:07:09 +08:00
|
|
|
if (! needsSkewMatrix && !_anchorPointInPoints.equals(Vec2::ZERO))
|
2012-06-08 14:17:39 +08:00
|
|
|
{
|
2014-07-02 03:36:53 +08:00
|
|
|
x += cy * -anchorPoint.x + -sx * -anchorPoint.y;
|
|
|
|
y += sy * -anchorPoint.x + cx * -anchorPoint.y;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// Build Transform Matrix
|
2012-11-14 18:05:15 +08:00
|
|
|
// Adjusted transform calculation for rotational skew
|
2014-04-08 23:05:33 +08:00
|
|
|
float mat[] = {
|
2014-02-23 11:16:42 +08:00
|
|
|
cy * _scaleX, sy * _scaleX, 0, 0,
|
|
|
|
-sx * _scaleY, cx * _scaleY, 0, 0,
|
|
|
|
0, 0, _scaleZ, 0,
|
|
|
|
x, y, z, 1 };
|
2013-12-19 20:32:22 +08:00
|
|
|
|
2014-04-08 23:05:33 +08:00
|
|
|
_transform.set(mat);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2014-07-01 08:19:51 +08:00
|
|
|
if(!_ignoreAnchorPointForPosition)
|
|
|
|
{
|
2014-07-02 03:36:53 +08:00
|
|
|
_transform.translate(anchorPoint.x, anchorPoint.y, 0);
|
2014-07-01 08:19:51 +08:00
|
|
|
}
|
|
|
|
|
2014-02-23 11:16:42 +08:00
|
|
|
// XXX
|
|
|
|
// FIX ME: Expensive operation.
|
|
|
|
// FIX ME: It should be done together with the rotationZ
|
|
|
|
if(_rotationY) {
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 rotY;
|
|
|
|
Mat4::createRotationY(CC_DEGREES_TO_RADIANS(_rotationY), &rotY);
|
2014-04-08 23:05:33 +08:00
|
|
|
_transform = _transform * rotY;
|
2014-02-23 11:16:42 +08:00
|
|
|
}
|
|
|
|
if(_rotationX) {
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 rotX;
|
|
|
|
Mat4::createRotationX(CC_DEGREES_TO_RADIANS(_rotationX), &rotX);
|
2014-04-08 23:05:33 +08:00
|
|
|
_transform = _transform * rotX;
|
2014-02-23 11:16:42 +08:00
|
|
|
}
|
|
|
|
|
2014-07-01 08:19:51 +08:00
|
|
|
if(!_ignoreAnchorPointForPosition)
|
|
|
|
{
|
2014-07-02 03:36:53 +08:00
|
|
|
_transform.translate(-anchorPoint.x, -anchorPoint.y, 0);
|
2014-07-01 08:19:51 +08:00
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// XXX: Try to inline skew
|
|
|
|
// If skew is needed, apply skew and then anchor point
|
2013-12-10 09:32:51 +08:00
|
|
|
if (needsSkewMatrix)
|
2012-06-08 14:17:39 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 skewMatrix(1, (float)tanf(CC_DEGREES_TO_RADIANS(_skewY)), 0, 0,
|
2014-04-10 23:12:29 +08:00
|
|
|
(float)tanf(CC_DEGREES_TO_RADIANS(_skewX)), 1, 0, 0,
|
|
|
|
0, 0, 1, 0,
|
|
|
|
0, 0, 0, 1);
|
2013-12-10 09:32:51 +08:00
|
|
|
|
2014-04-08 23:05:33 +08:00
|
|
|
_transform = _transform * skewMatrix;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// adjust anchor point
|
2014-05-15 01:07:09 +08:00
|
|
|
if (!_anchorPointInPoints.equals(Vec2::ZERO))
|
2012-06-08 14:17:39 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
// XXX: Argh, Mat4 needs a "translate" method.
|
2013-12-19 10:00:55 +08:00
|
|
|
// XXX: Although this is faster than multiplying a vec4 * mat4
|
2014-04-08 23:05:33 +08:00
|
|
|
_transform.m[12] += _transform.m[0] * -_anchorPointInPoints.x + _transform.m[4] * -_anchorPointInPoints.y;
|
|
|
|
_transform.m[13] += _transform.m[1] * -_anchorPointInPoints.x + _transform.m[5] * -_anchorPointInPoints.y;
|
2012-06-08 14:17:39 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-12-10 09:32:51 +08:00
|
|
|
|
2014-01-14 04:52:07 +08:00
|
|
|
if (_useAdditionalTransform)
|
2013-02-22 16:01:49 +08:00
|
|
|
{
|
2014-04-08 23:05:33 +08:00
|
|
|
_transform = _transform * _additionalTransform;
|
2013-02-22 16:01:49 +08:00
|
|
|
}
|
2014-01-04 09:54:07 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_transformDirty = false;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2014-01-04 09:54:07 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
return _transform;
|
2010-07-19 16:45:53 +08:00
|
|
|
}
|
2013-02-22 16:01:49 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void Node::setNodeToParentTransform(const Mat4& transform)
|
2013-12-21 08:33:31 +08:00
|
|
|
{
|
|
|
|
_transform = transform;
|
|
|
|
_transformDirty = false;
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = true;
|
2013-12-21 08:33:31 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::setAdditionalTransform(const AffineTransform& additionalTransform)
|
2013-12-10 09:32:51 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 tmp;
|
2014-04-08 23:05:33 +08:00
|
|
|
CGAffineToGL(additionalTransform, tmp.m);
|
2014-03-02 00:26:54 +08:00
|
|
|
setAdditionalTransform(&tmp);
|
2013-12-10 09:32:51 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void Node::setAdditionalTransform(Mat4* additionalTransform)
|
2013-02-20 22:33:28 +08:00
|
|
|
{
|
2014-03-02 00:26:54 +08:00
|
|
|
if(additionalTransform == nullptr) {
|
|
|
|
_useAdditionalTransform = false;
|
|
|
|
} else {
|
|
|
|
_additionalTransform = *additionalTransform;
|
|
|
|
_useAdditionalTransform = true;
|
|
|
|
}
|
2014-03-01 08:10:48 +08:00
|
|
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
2013-02-20 22:33:28 +08:00
|
|
|
}
|
2013-02-22 16:01:49 +08:00
|
|
|
|
2013-12-10 09:32:51 +08:00
|
|
|
|
|
|
|
AffineTransform Node::getParentToNodeAffineTransform() const
|
|
|
|
{
|
|
|
|
AffineTransform ret;
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 ret4 = getParentToNodeTransform();
|
2013-12-10 09:32:51 +08:00
|
|
|
|
2014-04-08 22:13:59 +08:00
|
|
|
GLToCGAffine(ret4.m,&ret);
|
2013-12-10 09:32:51 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
const Mat4& Node::getParentToNodeTransform() const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if ( _inverseDirty ) {
|
2014-05-01 01:59:36 +08:00
|
|
|
_inverse = _transform.getInversed();
|
2013-06-15 14:03:30 +08:00
|
|
|
_inverseDirty = false;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
return _inverse;
|
2010-07-19 16:45:53 +08:00
|
|
|
}
|
|
|
|
|
2013-12-10 09:32:51 +08:00
|
|
|
|
|
|
|
AffineTransform Node::getNodeToWorldAffineTransform() const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2013-12-10 09:32:51 +08:00
|
|
|
AffineTransform t = this->getNodeToParentAffineTransform();
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
for (Node *p = _parent; p != nullptr; p = p->getParent())
|
2013-12-10 09:32:51 +08:00
|
|
|
t = AffineTransformConcat(t, p->getNodeToParentAffineTransform());
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return t;
|
2010-07-19 16:45:53 +08:00
|
|
|
}
|
2010-07-21 17:40:10 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 Node::getNodeToWorldTransform() const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 t = this->getNodeToParentTransform();
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
for (Node *p = _parent; p != nullptr; p = p->getParent())
|
2014-04-04 18:41:29 +08:00
|
|
|
{
|
|
|
|
t = p->getNodeToParentTransform() * t;
|
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return t;
|
2010-07-19 16:45:53 +08:00
|
|
|
}
|
2010-07-21 17:40:10 +08:00
|
|
|
|
2013-12-10 09:32:51 +08:00
|
|
|
AffineTransform Node::getWorldToNodeAffineTransform() const
|
|
|
|
{
|
|
|
|
return AffineTransformInvert(this->getNodeToWorldAffineTransform());
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 Node::getWorldToNodeTransform() const
|
2013-07-17 09:16:04 +08:00
|
|
|
{
|
2014-05-01 01:59:36 +08:00
|
|
|
return getNodeToWorldTransform().getInversed();
|
2013-07-17 09:16:04 +08:00
|
|
|
}
|
|
|
|
|
2013-12-10 09:32:51 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 Node::convertToNodeSpace(const Vec2& worldPoint) const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 tmp = getWorldToNodeTransform();
|
|
|
|
Vec3 vec3(worldPoint.x, worldPoint.y, 0);
|
|
|
|
Vec3 ret;
|
2014-04-10 23:12:29 +08:00
|
|
|
tmp.transformPoint(vec3,&ret);
|
2014-05-15 01:07:09 +08:00
|
|
|
return Vec2(ret.x, ret.y);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 Node::convertToWorldSpace(const Vec2& nodePoint) const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 tmp = getNodeToWorldTransform();
|
|
|
|
Vec3 vec3(nodePoint.x, nodePoint.y, 0);
|
|
|
|
Vec3 ret;
|
2014-04-10 23:12:29 +08:00
|
|
|
tmp.transformPoint(vec3,&ret);
|
2014-05-15 01:07:09 +08:00
|
|
|
return Vec2(ret.x, ret.y);
|
2013-12-10 09:32:51 +08:00
|
|
|
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 Node::convertToNodeSpaceAR(const Vec2& worldPoint) const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 nodePoint = convertToNodeSpace(worldPoint);
|
2013-07-11 16:38:58 +08:00
|
|
|
return nodePoint - _anchorPointInPoints;
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 Node::convertToWorldSpaceAR(const Vec2& nodePoint) const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 pt = nodePoint + _anchorPointInPoints;
|
2012-04-19 14:35:52 +08:00
|
|
|
return convertToWorldSpace(pt);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
2012-03-14 14:55:17 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 Node::convertToWindowSpace(const Vec2& nodePoint) const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 worldPoint = this->convertToWorldSpace(nodePoint);
|
2013-07-12 06:24:23 +08:00
|
|
|
return Director::getInstance()->convertToUI(worldPoint);
|
2010-07-20 13:49:13 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
// convenience methods which take a Touch instead of Vec2
|
|
|
|
Vec2 Node::convertTouchToNodeSpace(Touch *touch) const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 point = touch->getLocation();
|
2012-04-19 14:35:52 +08:00
|
|
|
return this->convertToNodeSpace(point);
|
2010-07-30 16:35:07 +08:00
|
|
|
}
|
2014-04-15 14:29:12 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 Node::convertTouchToNodeSpaceAR(Touch *touch) const
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 point = touch->getLocation();
|
2012-04-19 14:35:52 +08:00
|
|
|
return this->convertToNodeSpaceAR(point);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
2010-07-30 16:35:07 +08:00
|
|
|
|
2013-10-18 15:34:13 +08:00
|
|
|
void Node::updateTransform()
|
|
|
|
{
|
2012-11-09 12:08:18 +08:00
|
|
|
// Recursively iterate over children
|
2013-12-19 08:56:59 +08:00
|
|
|
for( const auto &child: _children)
|
2013-11-28 16:02:03 +08:00
|
|
|
child->updateTransform();
|
2012-10-30 10:24:28 +08:00
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
Component* Node::getComponent(const std::string& name)
|
2013-06-04 17:38:43 +08:00
|
|
|
{
|
2013-09-07 07:00:24 +08:00
|
|
|
if( _componentContainer )
|
2014-05-28 17:41:34 +08:00
|
|
|
return _componentContainer->get(name);
|
2013-09-07 07:00:24 +08:00
|
|
|
return nullptr;
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
bool Node::addComponent(Component *component)
|
2013-06-04 17:38:43 +08:00
|
|
|
{
|
2013-09-07 07:00:24 +08:00
|
|
|
// lazy alloc
|
|
|
|
if( !_componentContainer )
|
|
|
|
_componentContainer = new ComponentContainer(this);
|
2014-05-28 17:41:34 +08:00
|
|
|
return _componentContainer->add(component);
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
bool Node::removeComponent(const std::string& name)
|
2013-06-04 17:38:43 +08:00
|
|
|
{
|
2013-09-07 07:00:24 +08:00
|
|
|
if( _componentContainer )
|
2014-05-28 17:41:34 +08:00
|
|
|
return _componentContainer->remove(name);
|
2013-09-07 07:00:24 +08:00
|
|
|
return false;
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|
|
|
|
|
2014-07-21 17:45:56 +08:00
|
|
|
bool Node::removeComponent(Component *component)
|
|
|
|
{
|
2014-08-06 13:51:16 +08:00
|
|
|
if (_componentContainer) {
|
|
|
|
return _componentContainer->remove(component);
|
|
|
|
}
|
|
|
|
return false;
|
2014-07-21 17:45:56 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Node::removeAllComponents()
|
2013-06-04 17:38:43 +08:00
|
|
|
{
|
2013-09-07 07:00:24 +08:00
|
|
|
if( _componentContainer )
|
|
|
|
_componentContainer->removeAll();
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|
|
|
|
|
2013-12-26 23:55:05 +08:00
|
|
|
#if CC_USE_PHYSICS
|
2014-06-27 17:30:21 +08:00
|
|
|
void Node::updatePhysicsBodyTransform(Scene* scene)
|
|
|
|
{
|
|
|
|
updatePhysicsBodyScale(scene);
|
|
|
|
updatePhysicsBodyPosition(scene);
|
|
|
|
updatePhysicsBodyRotation(scene);
|
|
|
|
}
|
2014-04-15 03:21:18 +08:00
|
|
|
|
2014-05-02 07:42:35 +08:00
|
|
|
void Node::updatePhysicsBodyPosition(Scene* scene)
|
2014-04-15 03:21:18 +08:00
|
|
|
{
|
|
|
|
if (_physicsBody != nullptr)
|
|
|
|
{
|
2014-05-02 07:42:35 +08:00
|
|
|
if (scene != nullptr && scene->getPhysicsWorld() != nullptr)
|
2014-04-15 03:21:18 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 pos = getParent() == scene ? getPosition() : scene->convertToNodeSpace(_parent->convertToWorldSpace(getPosition()));
|
2014-04-15 03:21:18 +08:00
|
|
|
_physicsBody->setPosition(pos);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_physicsBody->setPosition(getPosition());
|
|
|
|
}
|
|
|
|
}
|
2014-06-27 17:30:21 +08:00
|
|
|
|
|
|
|
for (Node* child : _children)
|
|
|
|
{
|
|
|
|
child->updatePhysicsBodyPosition(scene);
|
|
|
|
}
|
2014-04-15 03:21:18 +08:00
|
|
|
}
|
|
|
|
|
2014-05-02 07:42:35 +08:00
|
|
|
void Node::updatePhysicsBodyRotation(Scene* scene)
|
2014-04-15 03:21:18 +08:00
|
|
|
{
|
|
|
|
if (_physicsBody != nullptr)
|
|
|
|
{
|
2014-05-02 07:42:35 +08:00
|
|
|
if (scene != nullptr && scene->getPhysicsWorld() != nullptr)
|
2014-04-15 03:21:18 +08:00
|
|
|
{
|
|
|
|
float rotation = _rotationZ_X;
|
2014-05-02 07:42:35 +08:00
|
|
|
for (Node* parent = _parent; parent != scene; parent = parent->getParent())
|
2014-04-15 03:21:18 +08:00
|
|
|
{
|
|
|
|
rotation += parent->getRotation();
|
|
|
|
}
|
|
|
|
_physicsBody->setRotation(rotation);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_physicsBody->setRotation(_rotationZ_X);
|
|
|
|
}
|
|
|
|
}
|
2014-06-27 17:30:21 +08:00
|
|
|
|
|
|
|
for (auto child : _children)
|
|
|
|
{
|
|
|
|
child->updatePhysicsBodyRotation(scene);
|
|
|
|
child->updatePhysicsBodyPosition(scene);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::updatePhysicsBodyScale(Scene* scene)
|
|
|
|
{
|
|
|
|
if (_physicsBody != nullptr)
|
|
|
|
{
|
|
|
|
if (scene != nullptr && scene->getPhysicsWorld() != nullptr)
|
|
|
|
{
|
|
|
|
float scaleX = _scaleX / _physicsScaleStartX;
|
|
|
|
float scaleY = _scaleY / _physicsScaleStartY;
|
|
|
|
for (Node* parent = _parent; parent != scene; parent = parent->getParent())
|
|
|
|
{
|
|
|
|
scaleX *= parent->getScaleX();
|
|
|
|
scaleY *= parent->getScaleY();
|
|
|
|
}
|
|
|
|
_physicsBody->setScale(scaleX, scaleY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_physicsBody->setScale(_scaleX / _physicsScaleStartX, _scaleY / _physicsScaleStartY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto child : _children)
|
|
|
|
{
|
|
|
|
child->updatePhysicsBodyScale(scene);
|
|
|
|
}
|
2014-04-15 03:21:18 +08:00
|
|
|
}
|
|
|
|
|
2013-09-30 13:02:17 +08:00
|
|
|
void Node::setPhysicsBody(PhysicsBody* body)
|
|
|
|
{
|
2014-06-04 11:58:04 +08:00
|
|
|
if (_physicsBody == body)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-27 13:35:37 +08:00
|
|
|
if (body != nullptr)
|
|
|
|
{
|
2014-06-04 11:58:04 +08:00
|
|
|
if (body->getNode() != nullptr)
|
|
|
|
{
|
|
|
|
body->getNode()->setPhysicsBody(nullptr);
|
|
|
|
}
|
|
|
|
|
2014-02-27 13:35:37 +08:00
|
|
|
body->_node = this;
|
|
|
|
body->retain();
|
2014-02-28 15:31:25 +08:00
|
|
|
|
|
|
|
// physics rotation based on body position, but node rotation based on node anthor point
|
|
|
|
// it cann't support both of them, so I clear the anthor point to default.
|
2014-05-15 01:07:09 +08:00
|
|
|
if (!getAnchorPoint().equals(Vec2::ANCHOR_MIDDLE))
|
2014-02-28 15:31:25 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
CCLOG("Node warning: setPhysicsBody sets anchor point to Vec2::ANCHOR_MIDDLE.");
|
|
|
|
setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
2014-02-28 15:31:25 +08:00
|
|
|
}
|
2014-02-27 13:35:37 +08:00
|
|
|
}
|
2014-02-26 10:53:41 +08:00
|
|
|
|
2013-09-30 13:02:17 +08:00
|
|
|
if (_physicsBody != nullptr)
|
|
|
|
{
|
2014-02-26 10:53:41 +08:00
|
|
|
PhysicsWorld* world = _physicsBody->getWorld();
|
|
|
|
_physicsBody->removeFromWorld();
|
2013-11-01 16:26:03 +08:00
|
|
|
_physicsBody->_node = nullptr;
|
2013-09-30 13:02:17 +08:00
|
|
|
_physicsBody->release();
|
2014-02-26 10:53:41 +08:00
|
|
|
|
2014-02-27 13:35:37 +08:00
|
|
|
if (world != nullptr && body != nullptr)
|
2014-02-26 10:53:41 +08:00
|
|
|
{
|
|
|
|
world->addBody(body);
|
|
|
|
}
|
2013-09-30 13:02:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_physicsBody = body;
|
2014-06-27 17:30:21 +08:00
|
|
|
_physicsScaleStartX = _scaleX;
|
|
|
|
_physicsScaleStartY = _scaleY;
|
2014-04-15 03:21:18 +08:00
|
|
|
|
2014-02-27 13:35:37 +08:00
|
|
|
if (body != nullptr)
|
|
|
|
{
|
2014-04-15 03:21:18 +08:00
|
|
|
Node* node;
|
2014-05-02 07:42:35 +08:00
|
|
|
Scene* scene = nullptr;
|
2014-04-15 03:21:18 +08:00
|
|
|
for (node = this->getParent(); node != nullptr; node = node->getParent())
|
|
|
|
{
|
2014-05-02 07:42:35 +08:00
|
|
|
Scene* tmpScene = dynamic_cast<Scene*>(node);
|
|
|
|
if (tmpScene != nullptr && tmpScene->getPhysicsWorld() != nullptr)
|
2014-04-15 03:21:18 +08:00
|
|
|
{
|
2014-05-02 07:42:35 +08:00
|
|
|
scene = tmpScene;
|
2014-04-15 03:21:18 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-04 11:58:04 +08:00
|
|
|
if (scene != nullptr)
|
|
|
|
{
|
|
|
|
scene->getPhysicsWorld()->addBody(body);
|
|
|
|
}
|
|
|
|
|
2014-06-27 17:30:21 +08:00
|
|
|
updatePhysicsBodyTransform(scene);
|
2014-02-27 13:35:37 +08:00
|
|
|
}
|
2013-09-30 13:02:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
PhysicsBody* Node::getPhysicsBody() const
|
|
|
|
{
|
|
|
|
return _physicsBody;
|
|
|
|
}
|
|
|
|
#endif //CC_USE_PHYSICS
|
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
GLubyte Node::getOpacity(void) const
|
2013-02-27 09:38:30 +08:00
|
|
|
{
|
2013-02-27 14:48:19 +08:00
|
|
|
return _realOpacity;
|
2013-02-27 09:38:30 +08:00
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
GLubyte Node::getDisplayedOpacity() const
|
2013-02-27 09:38:30 +08:00
|
|
|
{
|
2013-02-27 14:48:19 +08:00
|
|
|
return _displayedOpacity;
|
2013-02-27 09:38:30 +08:00
|
|
|
}
|
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
void Node::setOpacity(GLubyte opacity)
|
2013-02-27 09:38:30 +08:00
|
|
|
{
|
2013-02-27 14:48:19 +08:00
|
|
|
_displayedOpacity = _realOpacity = opacity;
|
2013-02-27 09:38:30 +08:00
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
updateCascadeOpacity();
|
2013-02-27 09:38:30 +08:00
|
|
|
}
|
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
void Node::updateDisplayedOpacity(GLubyte parentOpacity)
|
2013-02-27 09:38:30 +08:00
|
|
|
{
|
2013-02-27 14:48:19 +08:00
|
|
|
_displayedOpacity = _realOpacity * parentOpacity/255.0;
|
2013-12-11 15:57:20 +08:00
|
|
|
updateColor();
|
|
|
|
|
2013-02-27 18:21:35 +08:00
|
|
|
if (_cascadeOpacityEnabled)
|
2013-02-27 14:48:19 +08:00
|
|
|
{
|
2013-12-19 17:05:59 +08:00
|
|
|
for(auto child : _children){
|
2013-12-06 18:07:16 +08:00
|
|
|
child->updateDisplayedOpacity(_displayedOpacity);
|
2013-12-19 10:33:04 +08:00
|
|
|
}
|
2013-02-27 09:38:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
bool Node::isCascadeOpacityEnabled(void) const
|
2013-02-27 15:30:49 +08:00
|
|
|
{
|
|
|
|
return _cascadeOpacityEnabled;
|
|
|
|
}
|
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
void Node::setCascadeOpacityEnabled(bool cascadeOpacityEnabled)
|
2013-02-27 15:30:49 +08:00
|
|
|
{
|
2013-12-11 15:57:20 +08:00
|
|
|
if (_cascadeOpacityEnabled == cascadeOpacityEnabled)
|
2013-12-06 18:07:16 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-27 15:30:49 +08:00
|
|
|
_cascadeOpacityEnabled = cascadeOpacityEnabled;
|
2013-12-06 18:07:16 +08:00
|
|
|
|
|
|
|
if (cascadeOpacityEnabled)
|
|
|
|
{
|
|
|
|
updateCascadeOpacity();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
disableCascadeOpacity();
|
|
|
|
}
|
2013-02-27 15:30:49 +08:00
|
|
|
}
|
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
void Node::updateCascadeOpacity()
|
|
|
|
{
|
|
|
|
GLubyte parentOpacity = 255;
|
|
|
|
|
|
|
|
if (_parent != nullptr && _parent->isCascadeOpacityEnabled())
|
|
|
|
{
|
|
|
|
parentOpacity = _parent->getDisplayedOpacity();
|
|
|
|
}
|
|
|
|
|
|
|
|
updateDisplayedOpacity(parentOpacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::disableCascadeOpacity()
|
|
|
|
{
|
|
|
|
_displayedOpacity = _realOpacity;
|
|
|
|
|
2013-12-19 17:05:59 +08:00
|
|
|
for(auto child : _children){
|
2013-12-11 15:57:20 +08:00
|
|
|
child->updateDisplayedOpacity(255);
|
2013-12-19 17:05:59 +08:00
|
|
|
}
|
2013-12-06 18:07:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const Color3B& Node::getColor(void) const
|
2013-02-27 09:38:30 +08:00
|
|
|
{
|
|
|
|
return _realColor;
|
|
|
|
}
|
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
const Color3B& Node::getDisplayedColor() const
|
2013-02-27 09:38:30 +08:00
|
|
|
{
|
|
|
|
return _displayedColor;
|
|
|
|
}
|
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
void Node::setColor(const Color3B& color)
|
2013-02-27 09:38:30 +08:00
|
|
|
{
|
|
|
|
_displayedColor = _realColor = color;
|
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
updateCascadeColor();
|
2013-02-27 09:38:30 +08:00
|
|
|
}
|
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
void Node::updateDisplayedColor(const Color3B& parentColor)
|
2013-02-27 09:38:30 +08:00
|
|
|
{
|
|
|
|
_displayedColor.r = _realColor.r * parentColor.r/255.0;
|
|
|
|
_displayedColor.g = _realColor.g * parentColor.g/255.0;
|
|
|
|
_displayedColor.b = _realColor.b * parentColor.b/255.0;
|
2013-12-11 15:57:20 +08:00
|
|
|
updateColor();
|
2013-02-27 09:38:30 +08:00
|
|
|
|
2013-02-27 14:48:19 +08:00
|
|
|
if (_cascadeColorEnabled)
|
|
|
|
{
|
2013-12-19 17:05:59 +08:00
|
|
|
for(const auto &child : _children){
|
2013-12-06 18:07:16 +08:00
|
|
|
child->updateDisplayedColor(_displayedColor);
|
2013-12-19 10:33:04 +08:00
|
|
|
}
|
2013-02-27 09:38:30 +08:00
|
|
|
}
|
|
|
|
}
|
2013-01-17 11:20:25 +08:00
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
bool Node::isCascadeColorEnabled(void) const
|
2013-02-27 15:30:49 +08:00
|
|
|
{
|
|
|
|
return _cascadeColorEnabled;
|
|
|
|
}
|
|
|
|
|
2013-12-06 18:07:16 +08:00
|
|
|
void Node::setCascadeColorEnabled(bool cascadeColorEnabled)
|
2013-02-27 15:30:49 +08:00
|
|
|
{
|
2013-12-06 18:07:16 +08:00
|
|
|
if (_cascadeColorEnabled == cascadeColorEnabled)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-27 15:30:49 +08:00
|
|
|
_cascadeColorEnabled = cascadeColorEnabled;
|
2013-12-06 18:07:16 +08:00
|
|
|
|
|
|
|
if (_cascadeColorEnabled)
|
|
|
|
{
|
|
|
|
updateCascadeColor();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
disableCascadeColor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::updateCascadeColor()
|
|
|
|
{
|
|
|
|
Color3B parentColor = Color3B::WHITE;
|
|
|
|
if (_parent && _parent->isCascadeColorEnabled())
|
|
|
|
{
|
|
|
|
parentColor = _parent->getDisplayedColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
updateDisplayedColor(parentColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::disableCascadeColor()
|
|
|
|
{
|
2013-12-19 17:05:59 +08:00
|
|
|
for(auto child : _children){
|
2013-12-11 15:57:20 +08:00
|
|
|
child->updateDisplayedColor(Color3B::WHITE);
|
2013-12-19 17:05:59 +08:00
|
|
|
}
|
2013-02-27 15:30:49 +08:00
|
|
|
}
|
|
|
|
|
2014-08-07 15:23:31 +08:00
|
|
|
void Node::setCameraMask(unsigned short mask, bool applyChildren)
|
|
|
|
{
|
|
|
|
_cameraMask = mask;
|
|
|
|
if (applyChildren)
|
|
|
|
{
|
|
|
|
for (auto child : _children) {
|
|
|
|
child->setCameraMask(mask, applyChildren);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-16 03:42:54 +08:00
|
|
|
__NodeRGBA::__NodeRGBA()
|
|
|
|
{
|
|
|
|
CCLOG("NodeRGBA deprecated.");
|
|
|
|
}
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_END
|