2010-07-07 15:24:44 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 cocos2d-x.org
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
CCNode::CCNode(void)
|
|
|
|
{
|
2010-07-08 10:26:58 +08:00
|
|
|
m_bIsRunning = false;
|
2010-07-07 15:24:44 +08:00
|
|
|
m_fRotation = 0.0f;
|
|
|
|
m_fScaleX = m_fScaleY = 1.0f;
|
|
|
|
m_tPosition = CGPoint(0,0);
|
|
|
|
m_tAnchorPointInPixels = m_tAnchorPoint = CGPoint(0,0);
|
|
|
|
m_tContentSize = CGSize(0,0);
|
|
|
|
|
2010-07-08 10:26:58 +08:00
|
|
|
// "whole screen" objects. like Scenes and Layers, should set isRelativeAnchorPoint to false
|
|
|
|
m_bIsRelativeAnchorPoint = true;
|
|
|
|
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
2010-07-07 15:24:44 +08:00
|
|
|
|
2010-07-08 14:00:51 +08:00
|
|
|
#ifdef CCX_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
2010-07-08 10:26:58 +08:00
|
|
|
m_bIsTransformGLDirty = true;
|
2010-07-07 15:24:44 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
m_fVertexZ = 0.0f;
|
|
|
|
|
2010-07-08 14:00:51 +08:00
|
|
|
// m_pGrid = NULL;
|
2010-07-07 15:24:44 +08:00
|
|
|
|
2010-07-08 14:00:51 +08:00
|
|
|
m_bIsVisible = true;
|
2010-07-07 15:24:44 +08:00
|
|
|
|
|
|
|
m_iTag = kCCNodeTagInvalid;
|
|
|
|
|
|
|
|
m_iZOrder = 0;
|
|
|
|
|
|
|
|
// lazy alloc
|
|
|
|
m_pCamera = NULL;
|
|
|
|
|
|
|
|
// children (lazy allocs)
|
2010-07-08 14:00:51 +08:00
|
|
|
m_pChildren = NULL;
|
2010-07-07 15:24:44 +08:00
|
|
|
|
|
|
|
// userData is always inited as nil
|
|
|
|
m_pUserData = NULL;
|
|
|
|
}
|
|
|
|
|
2010-07-08 14:00:51 +08:00
|
|
|
/*initialize*/
|
|
|
|
bool CCNode::init(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-08 10:26:58 +08:00
|
|
|
float CCNode::getRotation()
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
|
|
|
return m_fRotation;
|
|
|
|
}
|
|
|
|
|
|
|
|
CGPoint CCNode::getPosition()
|
|
|
|
{
|
|
|
|
return m_tPosition;
|
|
|
|
}
|
|
|
|
|
2010-07-08 10:26:58 +08:00
|
|
|
float CCNode::getScaleX()
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
|
|
|
return m_fScaleX;
|
|
|
|
}
|
|
|
|
|
2010-07-08 10:26:58 +08:00
|
|
|
float CCNode::getScaleY()
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
|
|
|
return m_fScaleY;
|
|
|
|
}
|
|
|
|
|
2010-07-08 14:00:51 +08:00
|
|
|
void CCNode::setVisibility(bool bIsVisible)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2010-07-08 14:00:51 +08:00
|
|
|
m_bIsVisible = bIsVisible;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
2010-07-08 14:00:51 +08:00
|
|
|
bool CCNode::getVisibility()
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2010-07-08 14:00:51 +08:00
|
|
|
return m_bIsVisible;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
//
|
|
|
|
//CCGridBase* CCNode::getGrid()
|
|
|
|
//{
|
|
|
|
// return m_pGrid;
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//void CCNode::setGrid(CCGridBase* pGrid)
|
|
|
|
//{
|
|
|
|
// if(/*!pGrid &&*/ m_pGrid)
|
|
|
|
// m_pGrid->release();
|
|
|
|
//
|
|
|
|
// m_pGrid = pGrid;
|
|
|
|
//
|
|
|
|
// if(m_pGrid)
|
|
|
|
// m_pGrid->retain();
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
// getters synthesized, setters explicit
|
2010-07-08 10:26:58 +08:00
|
|
|
void CCNode::setRotation(float newRotation)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
|
|
|
m_fRotation = newRotation;
|
2010-07-08 10:26:58 +08:00
|
|
|
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
2010-07-08 14:00:51 +08:00
|
|
|
#ifdef CCX_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
2010-07-08 10:26:58 +08:00
|
|
|
m_bIsTransformGLDirty = true;
|
|
|
|
#endif
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
2010-07-08 10:26:58 +08:00
|
|
|
void CCNode::setScaleX(float newScaleX)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
|
|
|
m_fScaleX = newScaleX;
|
2010-07-08 10:26:58 +08:00
|
|
|
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
2010-07-08 14:00:51 +08:00
|
|
|
#ifdef CCX_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
2010-07-08 10:26:58 +08:00
|
|
|
m_bIsTransformGLDirty = true;
|
|
|
|
#endif
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
2010-07-08 10:26:58 +08:00
|
|
|
void CCNode::setScaleY(float newScaleY)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
|
|
|
m_fScaleY = newScaleY;
|
2010-07-08 10:26:58 +08:00
|
|
|
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
2010-07-08 14:00:51 +08:00
|
|
|
#ifdef CCX_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
2010-07-08 10:26:58 +08:00
|
|
|
m_bIsTransformGLDirty = true;
|
|
|
|
#endif
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::setPosition(CGPoint newPosition)
|
|
|
|
{
|
|
|
|
m_tPosition = newPosition;
|
2010-07-08 10:26:58 +08:00
|
|
|
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
2010-07-08 14:00:51 +08:00
|
|
|
#ifdef CCX_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
2010-07-08 10:26:58 +08:00
|
|
|
m_bIsTransformGLDirty = true;
|
|
|
|
#endif
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
2010-07-08 10:26:58 +08:00
|
|
|
void CCNode::setIsRelativeAnchorPoint(bool newValue)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
|
|
|
m_bIsRelativeAnchorPoint = newValue;
|
2010-07-08 10:26:58 +08:00
|
|
|
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
2010-07-08 14:00:51 +08:00
|
|
|
#ifdef CCX_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
2010-07-08 10:26:58 +08:00
|
|
|
m_bIsTransformGLDirty = true;
|
|
|
|
#endif
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
2010-07-08 10:26:58 +08:00
|
|
|
bool CCNode::getIsRelativeAnchorPoint()
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
|
|
|
return m_bIsRelativeAnchorPoint;
|
|
|
|
}
|
|
|
|
|
2010-07-08 10:26:58 +08:00
|
|
|
void CCNode::setAnchorPoint(CGPoint point)
|
|
|
|
{
|
|
|
|
/*if( ! CGPointEqualToPoint(point, m_anchorPoint) )
|
|
|
|
{
|
|
|
|
m_anchorPoint = point;
|
|
|
|
this->m_anchorPointInPixels = ccp( m_contentSize.width * m_anchorPoint.x, m_contentSize.height * m_anchorPoint.y );
|
|
|
|
m_isTransformDirty = m_isInverseDirty = true;
|
2010-07-08 14:00:51 +08:00
|
|
|
#ifdef CCX_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
2010-07-08 10:26:58 +08:00
|
|
|
m_bIsTransformGLDirty = true;
|
|
|
|
#endif
|
|
|
|
}*/
|
|
|
|
}
|
2010-07-07 15:24:44 +08:00
|
|
|
|
2010-07-08 10:26:58 +08:00
|
|
|
CGPoint CCNode::getAnchorPoint()
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
|
|
|
return m_tAnchorPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::setContentSize(CGSize size)
|
|
|
|
{
|
|
|
|
//if( ! CGSizeEqualToSize(size, m_contentSize) )
|
|
|
|
//{
|
|
|
|
// m_contentSize = size;
|
|
|
|
// m_anchorPointInPixels = ccp( m_contentSize.width * m_anchorPoint.x, m_contentSize.height * m_anchorPoint.y );
|
2010-07-08 10:26:58 +08:00
|
|
|
// m_isTransformDirty = m_isInverseDirty = true;
|
2010-07-08 14:00:51 +08:00
|
|
|
// #ifdef CCX_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
2010-07-08 10:26:58 +08:00
|
|
|
// m_bIsTransformGLDirty = true;
|
|
|
|
// #endif
|
2010-07-07 15:24:44 +08:00
|
|
|
//}
|
|
|
|
}
|
|
|
|
|
|
|
|
CGSize CCNode::getContentSize()
|
|
|
|
{
|
|
|
|
return m_tContentSize;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
//CGRect CCNode::boundingBox()
|
|
|
|
//{
|
|
|
|
// CGRect rect = CGRectMake(0, 0, m_contentSize.width, m_contentSize.height);
|
|
|
|
// return CGRectApplyAffineTransform(rect, nodeToParentTransform());
|
|
|
|
//}
|
|
|
|
//
|
2010-07-08 10:26:58 +08:00
|
|
|
//float CCNode::scale()
|
2010-07-07 15:24:44 +08:00
|
|
|
//{
|
|
|
|
// UXAssert( m_scaleX == m_scaleY, L"CocosNode#scale. ScaleX != ScaleY. Don't know which one to return");
|
|
|
|
// return m_scaleX;
|
|
|
|
//}
|
|
|
|
|
2010-07-08 10:26:58 +08:00
|
|
|
void CCNode::setScale(float scale)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
|
|
|
m_fScaleX = m_fScaleY = scale;
|
2010-07-08 10:26:58 +08:00
|
|
|
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
2010-07-08 14:00:51 +08:00
|
|
|
#ifdef CCX_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
2010-07-08 10:26:58 +08:00
|
|
|
m_bIsTransformGLDirty = true;
|
|
|
|
#endif
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
//UxMutableArray* CCNode::children()
|
|
|
|
//{
|
|
|
|
// return m_pChildrenArray;
|
|
|
|
//}
|
|
|
|
|
|
|
|
void CCNode::setParent(CCNode* pParentNode)
|
|
|
|
{
|
|
|
|
m_pParent = pParentNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCNode* CCNode::getParent()
|
|
|
|
{
|
|
|
|
return m_pParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CCNode::getTag()
|
|
|
|
{
|
|
|
|
return m_iTag;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::setTag(int tag)
|
|
|
|
{
|
2010-07-08 10:26:58 +08:00
|
|
|
m_iTag = tag;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int CCNode::getZOrder()
|
|
|
|
{
|
|
|
|
return m_iZOrder;
|
|
|
|
}
|
|
|
|
|
2010-07-08 10:26:58 +08:00
|
|
|
void CCNode::setVertexZ(float z)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
|
|
|
m_fVertexZ = z;
|
|
|
|
}
|
|
|
|
|
2010-07-08 10:26:58 +08:00
|
|
|
float CCNode::getVertexZ()
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
|
|
|
return m_fVertexZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
CGPoint CCNode::getAnchorPointInPixels()
|
|
|
|
{
|
|
|
|
return m_tAnchorPointInPixels;
|
|
|
|
}
|
|
|
|
|
2010-07-08 10:26:58 +08:00
|
|
|
bool CCNode::getIsRunning()
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
|
|
|
return m_bIsRunning;
|
|
|
|
}
|
|
|
|
|