2010-12-18 16:12:59 +08:00
|
|
|
/****************************************************************************
|
2011-03-19 14:45:51 +08:00
|
|
|
Copyright (c) 2010-2011 cocos2d-x.org
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
|
|
|
Copyright (c) 2009 Valentin Milea
|
2011-07-01 15:48:05 +08:00
|
|
|
Copyright (c) 2011 Zynga 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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "CCNode.h"
|
2011-03-07 17:11:57 +08:00
|
|
|
#include "CCPointExtension.h"
|
2010-12-18 16:12:59 +08:00
|
|
|
#include "support/TransformUtils.h"
|
|
|
|
#include "CCCamera.h"
|
|
|
|
#include "effects/CCGrid.h"
|
|
|
|
#include "CCDirector.h"
|
|
|
|
#include "CCScheduler.h"
|
|
|
|
#include "CCTouch.h"
|
|
|
|
#include "CCActionManager.h"
|
|
|
|
|
2010-07-20 14:29:18 +08:00
|
|
|
#if CC_COCOSNODE_RENDER_SUBPIXEL
|
|
|
|
#define RENDER_IN_SUBPIXEL
|
|
|
|
#else
|
|
|
|
#define RENDER_IN_SUBPIXEL (int)
|
|
|
|
#endif
|
2010-12-18 16:12:59 +08:00
|
|
|
|
|
|
|
namespace cocos2d {
|
|
|
|
|
|
|
|
CCNode::CCNode(void)
|
2011-07-06 20:48:56 +08:00
|
|
|
: m_nZOrder(0)
|
2011-06-10 17:51:37 +08:00
|
|
|
, m_fVertexZ(0.0f)
|
|
|
|
, m_fRotation(0.0f)
|
|
|
|
, m_fScaleX(1.0f)
|
|
|
|
, m_fScaleY(1.0f)
|
|
|
|
, m_tPosition(CCPointZero)
|
|
|
|
, m_tPositionInPixels(CCPointZero)
|
2011-10-19 15:24:19 +08:00
|
|
|
, m_fSkewX(0.0)
|
|
|
|
, m_fSkewY(0.0)
|
2011-06-10 17:51:37 +08:00
|
|
|
// children (lazy allocs)
|
|
|
|
, m_pChildren(NULL)
|
|
|
|
// lazy alloc
|
|
|
|
, m_pCamera(NULL)
|
|
|
|
, m_pGrid(NULL)
|
|
|
|
, m_bIsVisible(true)
|
|
|
|
, m_tAnchorPoint(CCPointZero)
|
|
|
|
, m_tAnchorPointInPixels(CCPointZero)
|
|
|
|
, m_tContentSize(CCSizeZero)
|
|
|
|
, m_tContentSizeInPixels(CCSizeZero)
|
|
|
|
, m_bIsRunning(false)
|
|
|
|
, m_pParent(NULL)
|
2010-12-18 16:12:59 +08:00
|
|
|
// "whole screen" objects. like Scenes and Layers, should set isRelativeAnchorPoint to false
|
2011-06-10 17:51:37 +08:00
|
|
|
, m_bIsRelativeAnchorPoint(true)
|
|
|
|
, m_nTag(kCCNodeTagInvalid)
|
|
|
|
// userData is always inited as nil
|
|
|
|
, m_pUserData(NULL)
|
|
|
|
, m_bIsTransformDirty(true)
|
|
|
|
, m_bIsInverseDirty(true)
|
2010-07-20 14:29:18 +08:00
|
|
|
#ifdef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
2011-06-10 17:51:37 +08:00
|
|
|
, m_bIsTransformGLDirty(true)
|
2010-12-18 16:12:59 +08:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
// nothing
|
|
|
|
}
|
|
|
|
CCNode::~CCNode()
|
|
|
|
{
|
2010-08-02 15:42:07 +08:00
|
|
|
CCLOGINFO( "cocos2d: deallocing" );
|
2010-07-14 10:36:26 +08:00
|
|
|
|
|
|
|
// attributes
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SAFE_RELEASE(m_pCamera);
|
2010-07-14 10:36:26 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SAFE_RELEASE(m_pGrid);
|
2010-07-14 10:36:26 +08:00
|
|
|
|
2010-08-02 15:42:07 +08:00
|
|
|
if(m_pChildren && m_pChildren->count() > 0)
|
|
|
|
{
|
2011-04-21 14:46:15 +08:00
|
|
|
CCObject* child;
|
|
|
|
CCARRAY_FOREACH(m_pChildren, child)
|
|
|
|
{
|
|
|
|
CCNode* pChild = (CCNode*) child;
|
|
|
|
if (pChild)
|
|
|
|
{
|
|
|
|
pChild->m_pParent = NULL;
|
|
|
|
}
|
|
|
|
}
|
2010-08-02 15:42:07 +08:00
|
|
|
}
|
2010-07-14 10:36:26 +08:00
|
|
|
|
|
|
|
// children
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SAFE_RELEASE(m_pChildren);
|
2010-07-14 10:36:26 +08:00
|
|
|
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
2011-04-21 14:46:15 +08:00
|
|
|
void CCNode::arrayMakeObjectsPerformSelector(CCArray* pArray, callbackFunc func)
|
2010-12-18 16:12:59 +08:00
|
|
|
{
|
2010-07-14 10:36:26 +08:00
|
|
|
if(pArray && pArray->count() > 0)
|
|
|
|
{
|
2011-04-21 14:46:15 +08:00
|
|
|
CCObject* child;
|
2011-04-28 10:16:58 +08:00
|
|
|
CCARRAY_FOREACH(pArray, child)
|
2011-04-21 14:46:15 +08:00
|
|
|
{
|
|
|
|
CCNode* pNode = (CCNode*) child;
|
2011-05-30 16:49:08 +08:00
|
|
|
if(pNode && (0 != func))
|
2011-04-21 14:46:15 +08:00
|
|
|
{
|
|
|
|
(pNode->*func)();
|
|
|
|
}
|
|
|
|
}
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-01 15:48:05 +08:00
|
|
|
float CCNode::getSkewX()
|
|
|
|
{
|
|
|
|
return m_fSkewX;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::setSkewX(float newSkewX)
|
|
|
|
{
|
|
|
|
m_fSkewX = newSkewX;
|
|
|
|
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
|
|
|
#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
|
|
|
m_bIsTransformGLDirty = true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
float CCNode::getSkewY()
|
|
|
|
{
|
|
|
|
return m_fSkewY;
|
|
|
|
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
|
|
|
#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
|
|
|
m_bIsTransformGLDirty = true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::setSkewY(float newSkewY)
|
|
|
|
{
|
|
|
|
m_fSkewY = newSkewY;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-12-18 16:12:59 +08:00
|
|
|
/// zOrder getter
|
2011-07-06 20:48:56 +08:00
|
|
|
int CCNode::getZOrder()
|
2010-12-18 16:12:59 +08:00
|
|
|
{
|
2011-07-06 20:48:56 +08:00
|
|
|
return m_nZOrder;
|
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
|
2011-07-06 20:48:56 +08:00
|
|
|
void CCNode::setZOrder(int z)
|
2010-07-14 10:36:26 +08:00
|
|
|
{
|
2011-07-06 20:48:56 +08:00
|
|
|
m_nZOrder = z;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ertexZ getter
|
|
|
|
float CCNode::getVertexZ()
|
|
|
|
{
|
2011-08-02 15:45:27 +08:00
|
|
|
return m_fVertexZ / CC_CONTENT_SCALE_FACTOR();
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// vertexZ setter
|
|
|
|
void CCNode::setVertexZ(float var)
|
|
|
|
{
|
2010-12-24 15:21:57 +08:00
|
|
|
m_fVertexZ = var * CC_CONTENT_SCALE_FACTOR();
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// rotation getter
|
|
|
|
float CCNode::getRotation()
|
|
|
|
{
|
|
|
|
return m_fRotation;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// rotation setter
|
2010-07-12 17:56:06 +08:00
|
|
|
void CCNode::setRotation(float newRotation)
|
|
|
|
{
|
|
|
|
m_fRotation = newRotation;
|
|
|
|
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
2010-07-20 14:29:18 +08:00
|
|
|
#ifdef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
2010-07-14 16:30:25 +08:00
|
|
|
m_bIsTransformGLDirty = true;
|
|
|
|
#endif
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// scale getter
|
|
|
|
float CCNode::getScale(void)
|
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCAssert( m_fScaleX == m_fScaleY, "CCNode#scale. ScaleX != ScaleY. Don't know which one to return");
|
2010-08-19 15:29:38 +08:00
|
|
|
return m_fScaleX;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// scale setter
|
2010-07-12 17:56:06 +08:00
|
|
|
void CCNode::setScale(float scale)
|
|
|
|
{
|
|
|
|
m_fScaleX = m_fScaleY = scale;
|
|
|
|
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
2010-07-20 14:29:18 +08:00
|
|
|
#ifdef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
2010-07-14 16:30:25 +08:00
|
|
|
m_bIsTransformGLDirty = true;
|
|
|
|
#endif
|
2010-07-12 17:56:06 +08:00
|
|
|
}
|
2010-12-18 16:12:59 +08:00
|
|
|
|
|
|
|
/// scaleX getter
|
2010-07-08 10:26:58 +08:00
|
|
|
float CCNode::getScaleX()
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
|
|
|
return m_fScaleX;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// scaleX setter
|
2010-07-12 17:56:06 +08:00
|
|
|
void CCNode::setScaleX(float newScaleX)
|
|
|
|
{
|
|
|
|
m_fScaleX = newScaleX;
|
|
|
|
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
2010-07-20 14:29:18 +08:00
|
|
|
#ifdef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
2010-07-14 16:30:25 +08:00
|
|
|
m_bIsTransformGLDirty = true;
|
|
|
|
#endif
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
2010-12-18 16:12:59 +08:00
|
|
|
|
|
|
|
/// scaleY getter
|
2010-07-08 10:26:58 +08:00
|
|
|
float CCNode::getScaleY()
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
|
|
|
return m_fScaleY;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
2010-07-12 17:56:06 +08:00
|
|
|
|
|
|
|
/// scaleY setter
|
|
|
|
void CCNode::setScaleY(float newScaleY)
|
|
|
|
{
|
|
|
|
m_fScaleY = newScaleY;
|
|
|
|
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
2010-07-20 14:29:18 +08:00
|
|
|
#ifdef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
2010-07-14 16:30:25 +08:00
|
|
|
m_bIsTransformGLDirty = true;
|
|
|
|
#endif
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// position getter
|
2011-08-17 21:19:57 +08:00
|
|
|
const CCPoint& CCNode::getPosition()
|
2010-12-18 16:12:59 +08:00
|
|
|
{
|
|
|
|
return m_tPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// position setter
|
2011-08-17 21:19:57 +08:00
|
|
|
void CCNode::setPosition(const CCPoint& newPosition)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2010-07-12 17:56:06 +08:00
|
|
|
m_tPosition = newPosition;
|
2010-12-24 15:21:57 +08:00
|
|
|
if (CC_CONTENT_SCALE_FACTOR() == 1)
|
|
|
|
{
|
2011-01-05 11:24:52 +08:00
|
|
|
m_tPositionInPixels = m_tPosition;
|
2010-12-24 15:21:57 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-05 11:24:52 +08:00
|
|
|
m_tPositionInPixels = ccpMult(newPosition, CC_CONTENT_SCALE_FACTOR());
|
2010-12-24 15:21:57 +08:00
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
2010-07-20 14:29:18 +08:00
|
|
|
#ifdef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
2010-07-14 16:30:25 +08:00
|
|
|
m_bIsTransformGLDirty = true;
|
|
|
|
#endif
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
void CCNode::setPositionInPixels(const CCPoint& newPosition)
|
2010-12-24 15:21:57 +08:00
|
|
|
{
|
2010-12-31 14:56:24 +08:00
|
|
|
m_tPositionInPixels = newPosition;
|
2010-12-24 15:21:57 +08:00
|
|
|
|
|
|
|
if ( CC_CONTENT_SCALE_FACTOR() == 1)
|
|
|
|
{
|
2010-12-31 14:56:24 +08:00
|
|
|
m_tPosition = m_tPositionInPixels;
|
2010-12-24 15:21:57 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_tPosition = ccpMult(newPosition, 1/CC_CONTENT_SCALE_FACTOR());
|
|
|
|
}
|
|
|
|
|
|
|
|
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
|
|
|
|
|
|
|
#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
|
|
|
m_bIsTransformGLDirty = true;
|
|
|
|
#endif // CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
|
|
|
}
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
const CCPoint& CCNode::getPositionInPixels()
|
2010-12-31 14:56:24 +08:00
|
|
|
{
|
|
|
|
return m_tPositionInPixels;
|
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// children getter
|
2011-04-21 14:46:15 +08:00
|
|
|
CCArray* CCNode::getChildren()
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2010-07-12 17:56:06 +08:00
|
|
|
return m_pChildren;
|
|
|
|
}
|
|
|
|
|
2010-07-14 10:36:26 +08:00
|
|
|
/// camera getter: lazy alloc
|
|
|
|
CCCamera* CCNode::getCamera()
|
2010-07-12 17:56:06 +08:00
|
|
|
{
|
2010-12-18 16:12:59 +08:00
|
|
|
if (!m_pCamera)
|
|
|
|
{
|
|
|
|
m_pCamera = new CCCamera();
|
|
|
|
}
|
2010-07-14 10:36:26 +08:00
|
|
|
|
|
|
|
return m_pCamera;
|
2010-07-12 17:56:06 +08:00
|
|
|
}
|
|
|
|
|
2010-07-14 10:36:26 +08:00
|
|
|
|
2010-12-18 16:12:59 +08:00
|
|
|
/// grid getter
|
2010-07-14 10:36:26 +08:00
|
|
|
CCGridBase* CCNode::getGrid()
|
|
|
|
{
|
|
|
|
return m_pGrid;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
2010-07-12 17:56:06 +08:00
|
|
|
|
2010-07-14 10:36:26 +08:00
|
|
|
/// grid setter
|
|
|
|
void CCNode::setGrid(CCGridBase* pGrid)
|
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SAFE_RETAIN(pGrid);
|
|
|
|
CC_SAFE_RELEASE(m_pGrid);
|
2010-07-14 10:36:26 +08:00
|
|
|
m_pGrid = pGrid;
|
|
|
|
}
|
2010-07-07 15:24:44 +08:00
|
|
|
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// isVisible getter
|
|
|
|
bool CCNode::getIsVisible()
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2010-07-12 17:56:06 +08:00
|
|
|
return m_bIsVisible;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// isVisible setter
|
|
|
|
void CCNode::setIsVisible(bool var)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2010-07-12 17:56:06 +08:00
|
|
|
m_bIsVisible = var;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
|
|
|
|
/// anchorPoint getter
|
2011-08-17 21:19:57 +08:00
|
|
|
const CCPoint& CCNode::getAnchorPoint()
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2010-07-12 17:56:06 +08:00
|
|
|
return m_tAnchorPoint;
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
void CCNode::setAnchorPoint(const CCPoint& point)
|
2010-07-08 10:26:58 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
if( ! CCPoint::CCPointEqualToPoint(point, m_tAnchorPoint) )
|
2010-07-16 17:53:59 +08:00
|
|
|
{
|
|
|
|
m_tAnchorPoint = point;
|
2010-12-24 15:21:57 +08:00
|
|
|
m_tAnchorPointInPixels = ccp( m_tContentSizeInPixels.width * m_tAnchorPoint.x, m_tContentSizeInPixels.height * m_tAnchorPoint.y );
|
2010-12-18 16:12:59 +08:00
|
|
|
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
2010-07-20 14:29:18 +08:00
|
|
|
#ifdef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
2010-07-16 17:53:59 +08:00
|
|
|
m_bIsTransformGLDirty = true;
|
2010-12-18 16:12:59 +08:00
|
|
|
#endif
|
2010-07-16 17:53:59 +08:00
|
|
|
}
|
2010-07-12 17:56:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// anchorPointInPixels getter
|
2011-08-17 21:19:57 +08:00
|
|
|
const CCPoint& CCNode::getAnchorPointInPixels()
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2010-07-12 17:56:06 +08:00
|
|
|
return m_tAnchorPointInPixels;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
2010-07-12 17:56:06 +08:00
|
|
|
|
|
|
|
/// contentSize getter
|
2011-08-17 21:19:57 +08:00
|
|
|
const CCSize& CCNode::getContentSize()
|
2010-07-12 17:56:06 +08:00
|
|
|
{
|
|
|
|
return m_tContentSize;
|
|
|
|
}
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
void CCNode::setContentSize(const CCSize& size)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
if( ! CCSize::CCSizeEqualToSize(size, m_tContentSize) )
|
2010-07-16 17:53:59 +08:00
|
|
|
{
|
|
|
|
m_tContentSize = size;
|
2011-01-04 17:46:23 +08:00
|
|
|
|
2011-01-24 10:51:30 +08:00
|
|
|
if( CC_CONTENT_SCALE_FACTOR() == 1 )
|
|
|
|
{
|
|
|
|
m_tContentSizeInPixels = m_tContentSize;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
m_tContentSizeInPixels = CCSizeMake( size.width * CC_CONTENT_SCALE_FACTOR(), size.height * CC_CONTENT_SCALE_FACTOR() );
|
2011-01-04 17:46:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
m_tAnchorPointInPixels = ccp( m_tContentSizeInPixels.width * m_tAnchorPoint.x, m_tContentSizeInPixels.height * m_tAnchorPoint.y );
|
2010-12-18 16:12:59 +08:00
|
|
|
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
2010-07-20 14:29:18 +08:00
|
|
|
#ifdef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
2010-07-16 17:53:59 +08:00
|
|
|
m_bIsTransformGLDirty = true;
|
2010-12-18 16:12:59 +08:00
|
|
|
#endif
|
2010-07-16 17:53:59 +08:00
|
|
|
}
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
void CCNode::setContentSizeInPixels(const CCSize& size)
|
2010-12-24 15:21:57 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
if (! CCSize::CCSizeEqualToSize(size, m_tContentSizeInPixels))
|
2010-12-24 15:21:57 +08:00
|
|
|
{
|
|
|
|
m_tContentSizeInPixels = size;
|
|
|
|
|
|
|
|
if (CC_CONTENT_SCALE_FACTOR() == 1)
|
|
|
|
{
|
|
|
|
m_tContentSize = m_tContentSizeInPixels;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
m_tContentSize = CCSizeMake(size.width / CC_CONTENT_SCALE_FACTOR(), size.height / CC_CONTENT_SCALE_FACTOR());
|
2010-12-24 15:21:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
m_tAnchorPointInPixels = ccp(m_tContentSizeInPixels.width * m_tAnchorPoint.x, m_tContentSizeInPixels.height * m_tAnchorPoint.y);
|
|
|
|
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
|
|
|
|
|
|
|
#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
|
|
|
m_bIsTransformGLDirty = true;
|
|
|
|
#endif // CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
const CCSize& CCNode::getContentSizeInPixels()
|
2010-12-31 14:56:24 +08:00
|
|
|
{
|
|
|
|
return m_tContentSizeInPixels;
|
|
|
|
}
|
|
|
|
|
2010-07-07 15:24:44 +08:00
|
|
|
|
2011-01-31 06:59:03 +08:00
|
|
|
// isRunning getter
|
2010-07-12 17:56:06 +08:00
|
|
|
bool CCNode::getIsRunning()
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2010-07-12 17:56:06 +08:00
|
|
|
return m_bIsRunning;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// parent getter
|
|
|
|
CCNode * CCNode::getParent()
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
|
|
|
return m_pParent;
|
|
|
|
}
|
2010-07-12 17:56:06 +08:00
|
|
|
/// parent setter
|
|
|
|
void CCNode::setParent(CCNode * var)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2010-07-12 17:56:06 +08:00
|
|
|
m_pParent = var;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// isRelativeAnchorPoint getter
|
|
|
|
bool CCNode::getIsRelativeAnchorPoint()
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2010-07-12 17:56:06 +08:00
|
|
|
return m_bIsRelativeAnchorPoint;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
2010-07-12 17:56:06 +08:00
|
|
|
/// isRelativeAnchorPoint setter
|
|
|
|
void CCNode::setIsRelativeAnchorPoint(bool newValue)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2010-07-12 17:56:06 +08:00
|
|
|
m_bIsRelativeAnchorPoint = newValue;
|
|
|
|
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
2010-07-20 14:29:18 +08:00
|
|
|
#ifdef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
2010-07-14 16:30:25 +08:00
|
|
|
m_bIsTransformGLDirty = true;
|
|
|
|
#endif
|
2010-12-18 16:12:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// tag getter
|
|
|
|
int CCNode::getTag()
|
|
|
|
{
|
|
|
|
return m_nTag;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// tag setter
|
|
|
|
void CCNode::setTag(int var)
|
|
|
|
{
|
|
|
|
m_nTag = var;
|
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// userData getter
|
|
|
|
void * CCNode::getUserData()
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2010-07-12 17:56:06 +08:00
|
|
|
return m_pUserData;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// userData setter
|
|
|
|
void CCNode::setUserData(void *var)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2010-07-12 17:56:06 +08:00
|
|
|
m_pUserData = var;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
2010-12-18 16:12:59 +08:00
|
|
|
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCRect CCNode::boundingBox()
|
2010-07-20 14:29:18 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCRect ret = boundingBoxInPixels();
|
2010-12-24 15:21:57 +08:00
|
|
|
return CC_RECT_PIXELS_TO_POINTS(ret);
|
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCRect CCNode::boundingBoxInPixels()
|
2010-12-24 15:21:57 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCRect rect = CCRectMake(0, 0, m_tContentSizeInPixels.width, m_tContentSizeInPixels.height);
|
2011-03-15 10:27:16 +08:00
|
|
|
return CCRectApplyAffineTransform(rect, nodeToParentTransform());
|
2010-07-20 14:29:18 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
CCNode * CCNode::node(void)
|
|
|
|
{
|
2010-08-03 11:28:34 +08:00
|
|
|
CCNode * pRet = new CCNode();
|
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2010-07-14 10:36:26 +08:00
|
|
|
|
2010-07-09 18:24:08 +08:00
|
|
|
void CCNode::cleanup()
|
|
|
|
{
|
|
|
|
// actions
|
2010-07-14 10:36:26 +08:00
|
|
|
this->stopAllActions();
|
|
|
|
this->unscheduleAllSelectors();
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-08-02 14:46:06 +08:00
|
|
|
// timers
|
2010-07-14 10:36:26 +08:00
|
|
|
arrayMakeObjectsPerformSelector(m_pChildren, &CCNode::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
|
|
|
|
2010-08-06 16:05:19 +08:00
|
|
|
char * CCNode::description()
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2010-12-18 16:12:59 +08:00
|
|
|
char *ret = new char[100] ;
|
|
|
|
sprintf(ret, "<CCNode | Tag = %d>", m_nTag);
|
2010-07-15 11:39:05 +08:00
|
|
|
return ret;
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// lazy allocs
|
|
|
|
void CCNode::childrenAlloc(void)
|
|
|
|
{
|
2011-04-21 14:46:15 +08:00
|
|
|
m_pChildren = CCArray::arrayWithCapacity(4);
|
|
|
|
m_pChildren->retain();
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2011-07-06 20:48:56 +08:00
|
|
|
CCNode* CCNode::getChildByTag(int aTag)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCAssert( aTag != kCCNodeTagInvalid, "Invalid tag");
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-07-14 10:36:26 +08:00
|
|
|
if(m_pChildren && m_pChildren->count() > 0)
|
|
|
|
{
|
2011-04-21 14:46:15 +08:00
|
|
|
CCObject* child;
|
|
|
|
CCARRAY_FOREACH(m_pChildren, child)
|
|
|
|
{
|
|
|
|
CCNode* pNode = (CCNode*) child;
|
2010-07-14 11:18:05 +08:00
|
|
|
if(pNode && pNode->m_nTag == aTag)
|
2010-07-14 10:36:26 +08:00
|
|
|
return pNode;
|
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* "add" logic MUST only be on this method
|
|
|
|
* If a class want's to extend the 'addChild' behaviour it only needs
|
|
|
|
* to override this method
|
|
|
|
*/
|
2011-07-06 20:48:56 +08:00
|
|
|
void CCNode::addChild(CCNode *child, int zOrder, int tag)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCAssert( child != NULL, "Argument must be non-nil");
|
|
|
|
CCAssert( child->m_pParent == NULL, "child already added. It can't be added again");
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-07-14 10:36:26 +08:00
|
|
|
if( ! m_pChildren )
|
2010-08-02 15:42:07 +08:00
|
|
|
{
|
2010-07-14 10:36:26 +08:00
|
|
|
this->childrenAlloc();
|
2010-08-02 15:42:07 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-07-14 10:36:26 +08:00
|
|
|
this->insertChild(child, zOrder);
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-07-14 11:18:05 +08:00
|
|
|
child->m_nTag = tag;
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-07-14 10:36:26 +08:00
|
|
|
child->setParent(this);
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-07-14 10:36:26 +08:00
|
|
|
if( m_bIsRunning )
|
2010-08-02 15:42:07 +08:00
|
|
|
{
|
2010-07-14 10:36:26 +08:00
|
|
|
child->onEnter();
|
2010-12-24 15:21:57 +08:00
|
|
|
child->onEnterTransitionDidFinish();
|
2010-08-02 15:42:07 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2011-07-06 20:48:56 +08:00
|
|
|
void CCNode::addChild(CCNode *child, int zOrder)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCAssert( child != NULL, "Argument must be non-nil");
|
2010-12-24 15:21:57 +08:00
|
|
|
this->addChild(child, zOrder, child->m_nTag);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2010-12-24 15:21:57 +08:00
|
|
|
void CCNode::addChild(CCNode *child)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCAssert( child != NULL, "Argument must be non-nil");
|
2011-07-06 20:48:56 +08:00
|
|
|
this->addChild(child, child->m_nZOrder, child->m_nTag);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::removeFromParentAndCleanup(bool cleanup)
|
|
|
|
{
|
2010-07-14 10:36:26 +08:00
|
|
|
this->m_pParent->removeChild(this,cleanup);
|
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
|
|
|
|
*/
|
2010-07-14 10:36:26 +08:00
|
|
|
void CCNode::removeChild(CCNode* child, bool cleanup)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
|
|
|
// explicit nil handling
|
2010-07-14 10:36:26 +08:00
|
|
|
if (m_pChildren == NULL)
|
2010-08-02 15:42:07 +08:00
|
|
|
{
|
2010-07-09 18:24:08 +08:00
|
|
|
return;
|
2010-08-02 15:42:07 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-07-14 10:36:26 +08:00
|
|
|
if ( m_pChildren->containsObject(child) )
|
2010-08-02 15:42:07 +08:00
|
|
|
{
|
2010-07-14 10:36:26 +08:00
|
|
|
this->detachChild(child,cleanup);
|
2010-08-02 15:42:07 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2011-07-06 20:48:56 +08:00
|
|
|
void CCNode::removeChildByTag(int tag, bool cleanup)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCAssert( tag != kCCNodeTagInvalid, "Invalid tag");
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-07-14 10:36:26 +08:00
|
|
|
CCNode *child = this->getChildByTag(tag);
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-07-14 10:36:26 +08:00
|
|
|
if (child == NULL)
|
2010-08-02 15:42:07 +08:00
|
|
|
{
|
2010-07-14 10:36:26 +08:00
|
|
|
CCLOG("cocos2d: removeChildByTag: child not found!");
|
2010-08-02 15:42:07 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
else
|
2010-08-02 15:42:07 +08:00
|
|
|
{
|
2010-07-14 10:36:26 +08:00
|
|
|
this->removeChild(child, cleanup);
|
2010-08-02 15:42:07 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::removeAllChildrenWithCleanup(bool cleanup)
|
|
|
|
{
|
|
|
|
// not using detachChild improves speed here
|
2010-12-18 16:12:59 +08:00
|
|
|
if ( m_pChildren && m_pChildren->count() > 0 )
|
|
|
|
{
|
2011-04-21 14:46:15 +08:00
|
|
|
CCObject* child;
|
|
|
|
CCARRAY_FOREACH(m_pChildren, child)
|
2010-12-18 16:12:59 +08:00
|
|
|
{
|
2011-04-21 14:46:15 +08:00
|
|
|
CCNode* pNode = (CCNode*) child;
|
2010-12-18 16:12:59 +08:00
|
|
|
if (pNode)
|
|
|
|
{
|
2010-07-14 10:36:26 +08:00
|
|
|
// IMPORTANT:
|
|
|
|
// -1st do onExit
|
2010-12-18 16:12:59 +08:00
|
|
|
// -2nd cleanup
|
|
|
|
if(m_bIsRunning)
|
|
|
|
{
|
|
|
|
pNode->onExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cleanup)
|
|
|
|
{
|
|
|
|
pNode->cleanup();
|
|
|
|
}
|
|
|
|
// set parent nil at the end
|
|
|
|
pNode->setParent(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pChildren->removeAllObjects();
|
|
|
|
}
|
|
|
|
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::detachChild(CCNode *child, bool doCleanup)
|
|
|
|
{
|
|
|
|
// IMPORTANT:
|
|
|
|
// -1st do onExit
|
|
|
|
// -2nd cleanup
|
2010-07-14 10:36:26 +08:00
|
|
|
if (m_bIsRunning)
|
2010-08-02 15:42:07 +08:00
|
|
|
{
|
2010-07-14 10:36:26 +08:00
|
|
|
child->onExit();
|
2010-08-02 15:42:07 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +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)
|
2010-08-02 15:42:07 +08:00
|
|
|
{
|
2010-07-14 10:36:26 +08:00
|
|
|
child->cleanup();
|
2010-08-02 15:42:07 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-07-14 10:36:26 +08:00
|
|
|
// set parent nil at the end
|
|
|
|
child->setParent(NULL);
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-07-14 10:36:26 +08:00
|
|
|
m_pChildren->removeObject(child);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// helper used by reorderChild & add
|
2011-07-06 20:48:56 +08:00
|
|
|
void CCNode::insertChild(CCNode* child, int z)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2011-01-04 17:46:23 +08:00
|
|
|
unsigned int index = 0;
|
2011-04-21 14:46:15 +08:00
|
|
|
CCNode* a = (CCNode*) m_pChildren->lastObject();
|
2011-01-04 17:46:23 +08:00
|
|
|
if (!a || a->getZOrder() <= z)
|
|
|
|
{
|
|
|
|
m_pChildren->addObject(child);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-04-21 14:46:15 +08:00
|
|
|
CCObject* pObject;
|
|
|
|
CCARRAY_FOREACH(m_pChildren, pObject)
|
2011-01-04 17:46:23 +08:00
|
|
|
{
|
2011-04-21 14:46:15 +08:00
|
|
|
CCNode* pNode = (CCNode*) pObject;
|
2011-07-06 20:48:56 +08:00
|
|
|
if ( pNode && (pNode->m_nZOrder > z ))
|
2011-01-04 17:46:23 +08:00
|
|
|
{
|
2011-04-21 14:46:15 +08:00
|
|
|
m_pChildren->insertObject(child, index);
|
2011-01-04 17:46:23 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2011-01-04 17:46:23 +08:00
|
|
|
child->setZOrder(z);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2011-07-06 20:48:56 +08:00
|
|
|
void CCNode::reorderChild(CCNode *child, int zOrder)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCAssert( child != NULL, "Child must be non-nil");
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-07-14 10:36:26 +08:00
|
|
|
child->retain();
|
|
|
|
m_pChildren->removeObject(child);
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-07-14 10:36:26 +08:00
|
|
|
insertChild(child, zOrder);
|
2010-08-02 15:44:41 +08:00
|
|
|
child->release();
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2010-12-18 16:12:59 +08:00
|
|
|
void CCNode::draw()
|
|
|
|
{
|
2011-11-28 17:28:43 +08:00
|
|
|
//CCAssert(0);
|
2010-12-18 16:12:59 +08:00
|
|
|
// override me
|
|
|
|
// Only use- this function to draw your staff.
|
|
|
|
// DON'T draw your stuff outside this method
|
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
|
|
|
void CCNode::visit()
|
|
|
|
{
|
2010-09-24 18:10:32 +08:00
|
|
|
// quick return if not visible
|
2010-12-18 16:12:59 +08:00
|
|
|
if (!m_bIsVisible)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
glPushMatrix();
|
2010-08-17 14:25:41 +08:00
|
|
|
|
2010-12-18 16:12:59 +08:00
|
|
|
if (m_pGrid && m_pGrid->isActive())
|
|
|
|
{
|
|
|
|
m_pGrid->beforeDraw();
|
|
|
|
this->transformAncestors();
|
|
|
|
}
|
|
|
|
|
|
|
|
this->transform();
|
2010-08-04 10:36:37 +08:00
|
|
|
|
2011-04-21 14:46:15 +08:00
|
|
|
CCNode* pNode = NULL;
|
|
|
|
unsigned int i = 0;
|
2010-08-04 10:36:37 +08:00
|
|
|
|
2010-07-19 16:45:53 +08:00
|
|
|
if(m_pChildren && m_pChildren->count() > 0)
|
|
|
|
{
|
2010-09-24 18:10:32 +08:00
|
|
|
// draw children zOrder < 0
|
2011-04-21 14:46:15 +08:00
|
|
|
ccArray *arrayData = m_pChildren->data;
|
|
|
|
for( ; i < arrayData->num; i++ )
|
|
|
|
{
|
|
|
|
pNode = (CCNode*) arrayData->arr[i];
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2011-07-06 20:48:56 +08:00
|
|
|
if ( pNode && pNode->m_nZOrder < 0 )
|
2010-07-19 16:45:53 +08:00
|
|
|
{
|
|
|
|
pNode->visit();
|
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
else
|
2010-07-19 16:45:53 +08:00
|
|
|
{
|
2010-07-09 18:24:08 +08:00
|
|
|
break;
|
2010-07-19 16:45:53 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
2010-08-04 10:36:37 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-09-24 18:10:32 +08:00
|
|
|
// self draw
|
2010-08-04 10:36:37 +08:00
|
|
|
this->draw();
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-09-24 18:10:32 +08:00
|
|
|
// draw children zOrder >= 0
|
2010-12-18 16:12:59 +08:00
|
|
|
if (m_pChildren && m_pChildren->count() > 0)
|
2010-08-04 10:36:37 +08:00
|
|
|
{
|
2011-04-21 14:46:15 +08:00
|
|
|
ccArray *arrayData = m_pChildren->data;
|
|
|
|
for( ; i < arrayData->num; i++ )
|
|
|
|
{
|
|
|
|
pNode = (CCNode*) arrayData->arr[i];
|
2010-12-18 16:12:59 +08:00
|
|
|
if (pNode)
|
|
|
|
{
|
|
|
|
pNode->visit();
|
|
|
|
}
|
2010-07-19 16:45:53 +08:00
|
|
|
}
|
|
|
|
}
|
2010-08-17 14:25:41 +08:00
|
|
|
|
2010-12-18 16:12:59 +08:00
|
|
|
if (m_pGrid && m_pGrid->isActive())
|
|
|
|
{
|
|
|
|
m_pGrid->afterDraw(this);
|
|
|
|
}
|
2010-08-17 14:25:41 +08:00
|
|
|
|
2010-07-19 16:45:53 +08:00
|
|
|
glPopMatrix();
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::transformAncestors()
|
|
|
|
{
|
|
|
|
if( m_pParent != NULL )
|
|
|
|
{
|
|
|
|
m_pParent->transformAncestors();
|
|
|
|
m_pParent->transform();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::transform()
|
|
|
|
{
|
|
|
|
// transformations
|
|
|
|
|
|
|
|
#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
|
|
|
// BEGIN alternative -- using cached transform
|
|
|
|
//
|
2010-07-20 14:29:18 +08:00
|
|
|
if( m_bIsTransformGLDirty ) {
|
2011-03-07 17:11:57 +08:00
|
|
|
CCAffineTransform t = this->nodeToParentTransform();
|
2010-07-20 14:29:18 +08:00
|
|
|
CGAffineToGL(&t, m_pTransformGL);
|
|
|
|
m_bIsTransformGLDirty = false;
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2010-07-20 14:29:18 +08:00
|
|
|
glMultMatrixf(m_pTransformGL);
|
|
|
|
if( m_fVertexZ )
|
2010-08-02 15:42:07 +08:00
|
|
|
{
|
2010-07-20 14:29:18 +08:00
|
|
|
glTranslatef(0, 0, m_fVertexZ);
|
2010-08-02 15:42:07 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
|
|
|
// XXX: Expensive calls. Camera should be integrated into the cached affine matrix
|
2010-08-17 14:25:41 +08:00
|
|
|
if (m_pCamera && !(m_pGrid && m_pGrid->isActive())) {
|
2010-07-20 14:29:18 +08:00
|
|
|
bool translate = (m_tAnchorPointInPixels.x != 0.0f || m_tAnchorPointInPixels.y != 0.0f);
|
2010-07-09 18:24:08 +08:00
|
|
|
|
|
|
|
if( translate )
|
2010-08-02 15:42:07 +08:00
|
|
|
{
|
2010-12-24 15:21:57 +08:00
|
|
|
ccglTranslate(RENDER_IN_SUBPIXEL(m_tAnchorPointInPixels.x), RENDER_IN_SUBPIXEL(m_tAnchorPointInPixels.y), 0);
|
2010-08-02 15:42:07 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-07-20 14:29:18 +08:00
|
|
|
m_pCamera->locate();
|
2010-07-09 18:24:08 +08:00
|
|
|
|
|
|
|
if( translate )
|
2010-08-02 15:42:07 +08:00
|
|
|
{
|
2010-12-24 15:21:57 +08:00
|
|
|
ccglTranslate(RENDER_IN_SUBPIXEL(-m_tAnchorPointInPixels.x), RENDER_IN_SUBPIXEL(-m_tAnchorPointInPixels.y), 0);
|
2010-08-02 15:42:07 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// END alternative
|
|
|
|
|
|
|
|
#else
|
|
|
|
// BEGIN original implementation
|
|
|
|
//
|
|
|
|
// translate
|
2010-07-20 14:29:18 +08:00
|
|
|
if ( m_bIsRelativeAnchorPoint && (m_tAnchorPointInPixels.x != 0 || m_tAnchorPointInPixels.y != 0 ) )
|
|
|
|
glTranslatef( RENDER_IN_SUBPIXEL(-m_tAnchorPointInPixels.x), RENDER_IN_SUBPIXEL(-m_tAnchorPointInPixels.y), 0);
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-07-20 14:29:18 +08:00
|
|
|
if (m_tAnchorPointInPixels.x != 0 || m_tAnchorPointInPixels.y != 0)
|
2011-01-04 17:46:23 +08:00
|
|
|
glTranslatef( RENDER_IN_SUBPIXEL(m_tPositionInPixels.x + m_tAnchorPointInPixels.x), RENDER_IN_SUBPIXEL(m_tPositionInPixels.y + m_tAnchorPointInPixels.y), m_fVertexZ);
|
2010-12-24 15:21:57 +08:00
|
|
|
else if ( m_tPositionInPixels.x !=0 || m_tPositionInPixels.y !=0 || m_fVertexZ != 0)
|
2011-01-04 17:46:23 +08:00
|
|
|
glTranslatef( RENDER_IN_SUBPIXEL(m_tPositionInPixels.x), RENDER_IN_SUBPIXEL(m_tPositionInPixels.y), m_fVertexZ );
|
2010-07-09 18:24:08 +08:00
|
|
|
|
|
|
|
// rotate
|
2010-07-20 14:29:18 +08:00
|
|
|
if (m_fRotation != 0.0f )
|
|
|
|
glRotatef( -m_fRotation, 0.0f, 0.0f, 1.0f );
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2011-07-30 16:55:38 +08:00
|
|
|
// skew
|
|
|
|
if ( (skewX_ != 0.0f) || (skewY_ != 0.0f) )
|
|
|
|
{
|
|
|
|
CCAffineTransform skewMatrix = CCAffineTransformMake( 1.0f, tanf(CC_DEGREES_TO_RADIANS(skewY_)), tanf(CC_DEGREES_TO_RADIANS(skewX_)), 1.0f, 0.0f, 0.0f );
|
|
|
|
GLfloat glMatrix[16];
|
|
|
|
CCAffineToGL(&skewMatrix, glMatrix);
|
|
|
|
glMultMatrixf(glMatrix);
|
2011-07-01 15:48:05 +08:00
|
|
|
}
|
|
|
|
|
2010-07-09 18:24:08 +08:00
|
|
|
// scale
|
2010-07-20 14:29:18 +08:00
|
|
|
if (m_fScaleX != 1.0f || m_fScaleY != 1.0f)
|
|
|
|
glScalef( m_fScaleX, m_fScaleY, 1.0f );
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-08-17 14:25:41 +08:00
|
|
|
if ( m_pCamera && !(m_pGrid && m_pGrid->isActive()) )
|
2010-07-20 14:29:18 +08:00
|
|
|
m_pCamera->locate();
|
2010-07-09 18:24:08 +08:00
|
|
|
|
|
|
|
// restore and re-position point
|
2010-07-20 14:29:18 +08:00
|
|
|
if (m_tAnchorPointInPixels.x != 0.0f || m_tAnchorPointInPixels.y != 0.0f)
|
|
|
|
glTranslatef(RENDER_IN_SUBPIXEL(-m_tAnchorPointInPixels.x), RENDER_IN_SUBPIXEL(-m_tAnchorPointInPixels.y), 0);
|
2010-07-09 18:24:08 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// END original implementation
|
|
|
|
#endif
|
2010-07-20 14:29:18 +08:00
|
|
|
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCNode::onEnter()
|
|
|
|
{
|
2010-07-14 10:36:26 +08:00
|
|
|
arrayMakeObjectsPerformSelector(m_pChildren, &CCNode::onEnter);
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-07-14 10:36:26 +08:00
|
|
|
this->resumeSchedulerAndActions();
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-07-14 10:36:26 +08:00
|
|
|
m_bIsRunning = true;
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::onEnterTransitionDidFinish()
|
|
|
|
{
|
2010-07-14 10:36:26 +08:00
|
|
|
arrayMakeObjectsPerformSelector(m_pChildren, &CCNode::onEnterTransitionDidFinish);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::onExit()
|
|
|
|
{
|
2010-07-14 10:36:26 +08:00
|
|
|
this->pauseSchedulerAndActions();
|
|
|
|
|
|
|
|
m_bIsRunning = false;
|
|
|
|
|
|
|
|
arrayMakeObjectsPerformSelector(m_pChildren, &CCNode::onExit);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
2010-08-06 09:46:56 +08:00
|
|
|
CCAction * CCNode::runAction(CCAction* action)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCAssert( action != NULL, "Argument must be non-nil");
|
2010-11-16 15:12:09 +08:00
|
|
|
CCActionManager::sharedManager()->addAction(action, this, !m_bIsRunning);
|
2010-07-09 18:24:08 +08:00
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::stopAllActions()
|
|
|
|
{
|
2010-11-16 15:12:09 +08:00
|
|
|
CCActionManager::sharedManager()->removeAllActionsFromTarget(this);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2010-08-06 09:46:56 +08:00
|
|
|
void CCNode::stopAction(CCAction* action)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2010-11-16 15:12:09 +08:00
|
|
|
CCActionManager::sharedManager()->removeAction(action);
|
2010-08-06 09:46:56 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2011-07-06 20:48:56 +08:00
|
|
|
void CCNode::stopActionByTag(int tag)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCAssert( tag != kCCActionTagInvalid, "Invalid tag");
|
2010-11-16 15:12:09 +08:00
|
|
|
CCActionManager::sharedManager()->removeActionByTag(tag, this);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2011-07-06 20:48:56 +08:00
|
|
|
CCAction * CCNode::getActionByTag(int tag)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCAssert( tag != kCCActionTagInvalid, "Invalid tag");
|
2010-11-16 15:12:09 +08:00
|
|
|
return CCActionManager::sharedManager()->getActionByTag(tag, this);
|
2010-08-06 09:46:56 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2011-07-01 15:48:05 +08:00
|
|
|
unsigned int CCNode::numberOfRunningActions()
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2010-11-16 15:12:09 +08:00
|
|
|
return CCActionManager::sharedManager()->numberOfRunningActionsInTarget(this);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2010-07-14 16:30:25 +08:00
|
|
|
// CCNode - Callbacks
|
2010-07-09 18:24:08 +08:00
|
|
|
|
|
|
|
void CCNode::scheduleUpdate()
|
|
|
|
{
|
|
|
|
scheduleUpdateWithPriority(0);
|
|
|
|
}
|
|
|
|
|
2011-07-06 20:48:56 +08:00
|
|
|
void CCNode::scheduleUpdateWithPriority(int priority)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2010-11-16 15:12:09 +08:00
|
|
|
CCScheduler::sharedScheduler()->scheduleUpdateForTarget(this, priority, !m_bIsRunning);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::unscheduleUpdate()
|
|
|
|
{
|
2010-11-16 15:12:09 +08:00
|
|
|
CCScheduler::sharedScheduler()->unscheduleUpdateForTarget(this);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2010-07-14 11:52:27 +08:00
|
|
|
void CCNode::schedule(SEL_SCHEDULE selector)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2010-07-14 11:52:27 +08:00
|
|
|
this->schedule(selector, 0);
|
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-07-14 11:52:27 +08:00
|
|
|
void CCNode::schedule(SEL_SCHEDULE selector, ccTime interval)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2011-05-30 16:36:12 +08:00
|
|
|
CCAssert( selector, "Argument must be non-nil");
|
2011-03-07 17:11:57 +08:00
|
|
|
CCAssert( interval >=0, "Argument must be positive");
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-11-16 15:12:09 +08:00
|
|
|
CCScheduler::sharedScheduler()->scheduleSelector(selector, this, interval, !m_bIsRunning);
|
2010-07-14 11:52:27 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-07-14 11:52:27 +08:00
|
|
|
void CCNode::unschedule(SEL_SCHEDULE selector)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
|
|
|
// explicit nil handling
|
2011-01-24 10:51:30 +08:00
|
|
|
if (selector == 0)
|
2010-07-09 18:24:08 +08:00
|
|
|
return;
|
|
|
|
|
2010-11-16 15:12:09 +08:00
|
|
|
CCScheduler::sharedScheduler()->unscheduleSelector(selector, this);
|
2010-07-14 11:52:27 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
|
|
|
void CCNode::unscheduleAllSelectors()
|
|
|
|
{
|
2010-11-16 15:12:09 +08:00
|
|
|
CCScheduler::sharedScheduler()->unscheduleAllSelectorsForTarget(this);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::resumeSchedulerAndActions()
|
|
|
|
{
|
2010-11-16 15:12:09 +08:00
|
|
|
CCScheduler::sharedScheduler()->resumeTarget(this);
|
|
|
|
CCActionManager::sharedManager()->resumeTarget(this);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::pauseSchedulerAndActions()
|
|
|
|
{
|
2010-11-16 15:12:09 +08:00
|
|
|
CCScheduler::sharedScheduler()->pauseTarget(this);
|
|
|
|
CCActionManager::sharedManager()->pauseTarget(this);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2010-08-30 15:45:39 +08:00
|
|
|
void CCNode::selectorProtocolRetain(void)
|
|
|
|
{
|
|
|
|
retain();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::selectorProtocolRelease(void)
|
|
|
|
{
|
|
|
|
release();
|
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCAffineTransform CCNode::nodeToParentTransform(void)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2011-07-01 15:48:05 +08:00
|
|
|
if (m_bIsTransformDirty) {
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
m_tTransform = CCAffineTransformIdentity;
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
if( ! m_bIsRelativeAnchorPoint && ! CCPoint::CCPointEqualToPoint(m_tAnchorPointInPixels, CCPointZero) )
|
2011-07-01 15:48:05 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
m_tTransform = CCAffineTransformTranslate(m_tTransform, m_tAnchorPointInPixels.x, m_tAnchorPointInPixels.y);
|
2011-07-01 15:48:05 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2011-07-01 15:48:05 +08:00
|
|
|
if(! CCPoint::CCPointEqualToPoint(m_tPositionInPixels, CCPointZero))
|
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
m_tTransform = CCAffineTransformTranslate(m_tTransform, m_tPositionInPixels.x, m_tPositionInPixels.y);
|
2011-07-01 15:48:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if(m_fRotation != 0)
|
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
m_tTransform = CCAffineTransformRotate(m_tTransform, -CC_DEGREES_TO_RADIANS(m_fRotation));
|
2011-07-01 15:48:05 +08:00
|
|
|
}
|
|
|
|
|
2011-07-30 16:55:38 +08:00
|
|
|
if(m_fSkewX != 0 || m_fSkewY != 0)
|
|
|
|
{
|
|
|
|
// create a skewed coordinate system
|
|
|
|
CCAffineTransform skew = CCAffineTransformMake(1.0f, tanf(CC_DEGREES_TO_RADIANS(m_fSkewY)), tanf(CC_DEGREES_TO_RADIANS(m_fSkewX)), 1.0f, 0.0f, 0.0f);
|
|
|
|
// apply the skew to the transform
|
|
|
|
m_tTransform = CCAffineTransformConcat(skew, m_tTransform);
|
2011-07-01 15:48:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if(! (m_fScaleX == 1 && m_fScaleY == 1))
|
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
m_tTransform = CCAffineTransformScale(m_tTransform, m_fScaleX, m_fScaleY);
|
2011-07-01 15:48:05 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2011-07-01 15:48:05 +08:00
|
|
|
if(! CCPoint::CCPointEqualToPoint(m_tAnchorPointInPixels, CCPointZero))
|
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
m_tTransform = CCAffineTransformTranslate(m_tTransform, -m_tAnchorPointInPixels.x, -m_tAnchorPointInPixels.y);
|
2011-07-01 15:48:05 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-07-19 16:45:53 +08:00
|
|
|
m_bIsTransformDirty = false;
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2010-07-19 16:45:53 +08:00
|
|
|
return m_tTransform;
|
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCAffineTransform CCNode::parentToNodeTransform(void)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2010-07-19 16:45:53 +08:00
|
|
|
if ( m_bIsInverseDirty ) {
|
2011-03-07 17:11:57 +08:00
|
|
|
m_tInverse = CCAffineTransformInvert(this->nodeToParentTransform());
|
2010-07-19 16:45:53 +08:00
|
|
|
m_bIsInverseDirty = false;
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2010-07-19 16:45:53 +08:00
|
|
|
return m_tInverse;
|
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCAffineTransform CCNode::nodeToWorldTransform()
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCAffineTransform t = this->nodeToParentTransform();
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-07-19 16:45:53 +08:00
|
|
|
for (CCNode *p = m_pParent; p != NULL; p = p->getParent())
|
2011-03-07 17:11:57 +08:00
|
|
|
t = CCAffineTransformConcat(t, p->nodeToParentTransform());
|
2010-07-09 18:24:08 +08:00
|
|
|
|
|
|
|
return t;
|
2010-07-19 16:45:53 +08:00
|
|
|
}
|
2010-07-21 17:40:10 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCAffineTransform CCNode::worldToNodeTransform(void)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
return CCAffineTransformInvert(this->nodeToWorldTransform());
|
2010-07-19 16:45:53 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
CCPoint CCNode::convertToNodeSpace(const CCPoint& worldPoint)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCPoint ret;
|
2011-01-24 10:51:30 +08:00
|
|
|
if(CC_CONTENT_SCALE_FACTOR() == 1)
|
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
ret = CCPointApplyAffineTransform(worldPoint, worldToNodeTransform());
|
2011-01-24 10:51:30 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = ccpMult(worldPoint, CC_CONTENT_SCALE_FACTOR());
|
2011-03-07 17:11:57 +08:00
|
|
|
ret = CCPointApplyAffineTransform(ret, worldToNodeTransform());
|
2011-01-24 10:51:30 +08:00
|
|
|
ret = ccpMult(ret, 1/CC_CONTENT_SCALE_FACTOR());
|
|
|
|
}
|
|
|
|
|
2010-12-24 15:21:57 +08:00
|
|
|
return ret;
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
CCPoint CCNode::convertToWorldSpace(const CCPoint& nodePoint)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCPoint ret;
|
2011-01-24 10:51:30 +08:00
|
|
|
if(CC_CONTENT_SCALE_FACTOR() == 1)
|
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
ret = CCPointApplyAffineTransform(nodePoint, nodeToWorldTransform());
|
2011-01-24 10:51:30 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = ccpMult( nodePoint, CC_CONTENT_SCALE_FACTOR() );
|
2011-03-07 17:11:57 +08:00
|
|
|
ret = CCPointApplyAffineTransform(ret, nodeToWorldTransform());
|
2011-01-24 10:51:30 +08:00
|
|
|
ret = ccpMult( ret, 1/CC_CONTENT_SCALE_FACTOR() );
|
|
|
|
}
|
|
|
|
|
2010-12-24 15:21:57 +08:00
|
|
|
return ret;
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
CCPoint CCNode::convertToNodeSpaceAR(const CCPoint& worldPoint)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCPoint nodePoint = convertToNodeSpace(worldPoint);
|
|
|
|
CCPoint anchorInPoints;
|
2011-01-24 10:51:30 +08:00
|
|
|
if( CC_CONTENT_SCALE_FACTOR() == 1 )
|
|
|
|
{
|
|
|
|
anchorInPoints = m_tAnchorPointInPixels;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
anchorInPoints = ccpMult( m_tAnchorPointInPixels, 1/CC_CONTENT_SCALE_FACTOR() );
|
|
|
|
}
|
|
|
|
|
2010-12-24 15:21:57 +08:00
|
|
|
return ccpSub(nodePoint, anchorInPoints);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
CCPoint CCNode::convertToWorldSpaceAR(const CCPoint& nodePoint)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCPoint anchorInPoints;
|
2011-01-24 10:51:30 +08:00
|
|
|
if( CC_CONTENT_SCALE_FACTOR() == 1 )
|
|
|
|
{
|
|
|
|
anchorInPoints = m_tAnchorPointInPixels;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
anchorInPoints = ccpMult( m_tAnchorPointInPixels, 1/CC_CONTENT_SCALE_FACTOR() );
|
|
|
|
}
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
CCPoint pt = ccpAdd(nodePoint, anchorInPoints);
|
|
|
|
return convertToWorldSpace(pt);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
2011-08-17 21:19:57 +08:00
|
|
|
CCPoint CCNode::convertToWindowSpace(const CCPoint& nodePoint)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCPoint worldPoint = this->convertToWorldSpace(nodePoint);
|
2010-11-11 11:18:58 +08:00
|
|
|
return CCDirector::sharedDirector()->convertToUI(worldPoint);
|
2010-07-20 13:49:13 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
// convenience methods which take a CCTouch instead of CCPoint
|
|
|
|
CCPoint CCNode::convertTouchToNodeSpace(CCTouch *touch)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCPoint point = touch->locationInView(touch->view());
|
2010-11-11 11:18:58 +08:00
|
|
|
point = CCDirector::sharedDirector()->convertToGL(point);
|
2010-07-30 16:35:07 +08:00
|
|
|
return this->convertToNodeSpace(point);
|
|
|
|
}
|
2011-03-07 17:11:57 +08:00
|
|
|
CCPoint CCNode::convertTouchToNodeSpaceAR(CCTouch *touch)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCPoint point = touch->locationInView(touch->view());
|
2010-11-11 11:18:58 +08:00
|
|
|
point = CCDirector::sharedDirector()->convertToGL(point);
|
2010-07-30 16:35:07 +08:00
|
|
|
return this->convertToNodeSpaceAR(point);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
2010-07-30 16:35:07 +08:00
|
|
|
|
2010-12-18 16:12:59 +08:00
|
|
|
}//namespace cocos2d
|