issue #1310: syncronize base_nodes

This commit is contained in:
minggo 2012-06-08 14:17:39 +08:00
parent cc16320445
commit 9a600c6221
2 changed files with 25 additions and 17 deletions

View File

@ -72,7 +72,7 @@ CCNode::CCNode(void)
, m_bIsRunning(false)
, m_pParent(NULL)
// "whole screen" objects. like Scenes and Layers, should set isRelativeAnchorPoint to false
, m_bIsRelativeAnchorPoint(true)
, m_bIgnoreAnchorPointForPosition(false)
, m_nTag(kCCNodeTagInvalid)
// userData is always inited as nil
, m_pUserData(NULL)
@ -392,15 +392,18 @@ void CCNode::setParent(CCNode * var)
}
/// isRelativeAnchorPoint getter
bool CCNode::getIsRelativeAnchorPoint()
bool CCNode::getIgnoreAnchorPointForPosition()
{
return m_bIsRelativeAnchorPoint;
return m_bIgnoreAnchorPointForPosition;
}
/// isRelativeAnchorPoint setter
void CCNode::setIsRelativeAnchorPoint(bool newValue)
void CCNode::setIgnoreAnchorPointForPosition(bool newValue)
{
m_bIsRelativeAnchorPoint = newValue;
m_bIsTransformDirty = m_bIsInverseDirty = true;
if (newValue != m_bIgnoreAnchorPointForPosition)
{
m_bIgnoreAnchorPointForPosition = newValue;
m_bIsTransformDirty = m_bIsInverseDirty = true;
}
}
/// tag getter
@ -969,20 +972,23 @@ void CCNode::pauseSchedulerAndActions()
CCAffineTransform CCNode::nodeToParentTransform(void)
{
if ( m_bIsTransformDirty ) {
if (m_bIsTransformDirty)
{
// Translate values
float x = m_tPosition.x;
float y = m_tPosition.y;
if ( !m_bIsRelativeAnchorPoint ) {
if (m_bIgnoreAnchorPointForPosition)
{
x += m_tAnchorPointInPoints.x;
y += m_tAnchorPointInPoints.y;
}
// Rotation values
float c = 1, s = 0;
if( m_fRotation ) {
if (m_fRotation)
{
float radians = -CC_DEGREES_TO_RADIANS(m_fRotation);
c = cosf(radians);
s = sinf(radians);
@ -993,7 +999,8 @@ CCAffineTransform CCNode::nodeToParentTransform(void)
// optimization:
// inline anchor point calculation if skew is not needed
if( !needsSkewMatrix && !CCPoint::CCPointEqualToPoint(m_tAnchorPointInPoints, CCPointZero) ) {
if (! needsSkewMatrix && !CCPoint::CCPointEqualToPoint(m_tAnchorPointInPoints, CCPointZero))
{
x += c * -m_tAnchorPointInPoints.x * m_fScaleX + -s * -m_tAnchorPointInPoints.y * m_fScaleY;
y += s * -m_tAnchorPointInPoints.x * m_fScaleX + c * -m_tAnchorPointInPoints.y * m_fScaleY;
}
@ -1006,15 +1013,18 @@ CCAffineTransform CCNode::nodeToParentTransform(void)
// XXX: Try to inline skew
// If skew is needed, apply skew and then anchor point
if( needsSkewMatrix ) {
if (needsSkewMatrix)
{
CCAffineTransform skewMatrix = CCAffineTransformMake(1.0f, tanf(CC_DEGREES_TO_RADIANS(m_fSkewY)),
tanf(CC_DEGREES_TO_RADIANS(m_fSkewX)), 1.0f,
0.0f, 0.0f );
m_tTransform = CCAffineTransformConcat(skewMatrix, m_tTransform);
// adjust anchor point
if( ! CCPoint::CCPointEqualToPoint(m_tAnchorPointInPoints, CCPointZero) )
if (! CCPoint::CCPointEqualToPoint(m_tAnchorPointInPoints, CCPointZero))
{
m_tTransform = CCAffineTransformTranslate(m_tTransform, -m_tAnchorPointInPoints.x, -m_tAnchorPointInPoints.y);
}
}
m_bIsTransformDirty = false;

View File

@ -259,11 +259,9 @@ class CC_DLL CCNode : public CCObject
/** A weak reference to the parent */
CC_PROPERTY(CCNode *, m_pParent, Parent)
/** If true the transformtions will be relative to it's anchor point.
* Sprites, Labels and any other sizeble object use it have it enabled by default.
* Scenes, Layers and other "whole screen" object don't use it, have it disabled by default.
*/
CC_PROPERTY(bool, m_bIsRelativeAnchorPoint, IsRelativeAnchorPoint)
// If ture, the Anchor Point will be (0,0) when you position the CCNode.
// Used by CCLayer and CCScene
CC_PROPERTY(bool, m_bIgnoreAnchorPointForPosition, IgnoreAnchorPointForPosition);
/** A tag used to identify the node easily */
CC_PROPERTY(int, m_nTag, Tag)