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 16:23:06 +08:00
|
|
|
:m_bIsRunning(false)
|
|
|
|
,m_fRotation(0.0f)
|
|
|
|
,m_fScaleX(1.0f)
|
|
|
|
,m_fScaleY(1.0f)
|
|
|
|
,m_tPosition(CGPoint(0,0))
|
|
|
|
,m_tAnchorPointInPixels(CGPoint(0,0))
|
|
|
|
,m_tAnchorPoint(CGPoint(0,0))
|
|
|
|
,m_tContentSize(CGSize(0,0))
|
|
|
|
// "whole screen" objects. like Scenes and Layers, should set isRelativeAnchorPoint to false
|
|
|
|
,m_bIsRelativeAnchorPoint(true)
|
|
|
|
,m_bIsTransformDirty(true)
|
|
|
|
,m_bIsInverseDirty(true)
|
|
|
|
#ifdef CCX_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
|
|
|
,m_bIsTransformGLDirty(true)
|
|
|
|
#endif
|
|
|
|
,m_fVertexZ(0.0f)
|
|
|
|
,m_pGrid(NULL)
|
|
|
|
,m_bIsVisible(true)
|
|
|
|
,m_iTag(kCCNodeTagInvalid)
|
|
|
|
,m_iZOrder(0)
|
|
|
|
// lazy alloc
|
|
|
|
,m_pCamera(NULL)
|
|
|
|
// children (lazy allocs)
|
|
|
|
,m_pChildren(NULL)
|
|
|
|
// userData is always inited as nil
|
|
|
|
,m_pUserData(NULL)
|
2010-07-08 14:00:51 +08:00
|
|
|
{
|
2010-07-09 16:22:02 +08:00
|
|
|
// nothing
|
2010-07-08 14:00:51 +08:00
|
|
|
}
|
2010-07-09 18:24:08 +08:00
|
|
|
/// @todo
|
|
|
|
CCNode::~CCNode()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2010-07-08 14:00:51 +08:00
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
|
|
|
|
/// zOrder getter
|
|
|
|
int CCNode::getZOrder()
|
|
|
|
{
|
|
|
|
return m_iZOrder;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ertexZ getter
|
|
|
|
float CCNode::getVertexZ()
|
|
|
|
{
|
|
|
|
return m_fVertexZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// vertexZ setter
|
|
|
|
void CCNode::setVertexZ(float var)
|
|
|
|
{
|
|
|
|
m_fVertexZ = var;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// rotation getter
|
2010-07-08 10:26:58 +08:00
|
|
|
float CCNode::getRotation()
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
|
|
|
return m_fRotation;
|
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// rotation setter
|
|
|
|
void CCNode::setRotation(float newRotation)
|
|
|
|
{
|
|
|
|
m_fRotation = newRotation;
|
|
|
|
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
|
|
|
#ifdef CCX_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
|
|
|
m_bIsTransformGLDirty = true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// scale getter
|
|
|
|
float CCNode::getScale(void)
|
|
|
|
{
|
|
|
|
///@todo NSAssert( scaleX_ == scaleY_, @"CCNode#scale. ScaleX != ScaleY. Don't know which one to return");
|
|
|
|
return m_fScale;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// scale setter
|
|
|
|
void CCNode::setScale(float scale)
|
|
|
|
{
|
|
|
|
m_fScaleX = m_fScaleY = scale;
|
|
|
|
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
|
|
|
#ifdef CCX_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
|
|
|
m_bIsTransformGLDirty = true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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-07-12 17:56:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// scaleX setter
|
|
|
|
void CCNode::setScaleX(float newScaleX)
|
|
|
|
{
|
|
|
|
m_fScaleX = newScaleX;
|
|
|
|
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
|
|
|
#ifdef CCX_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
|
|
|
m_bIsTransformGLDirty = true;
|
|
|
|
#endif
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
2010-07-12 17:56:06 +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-07-12 17:56:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// scaleY setter
|
|
|
|
void CCNode::setScaleY(float newScaleY)
|
|
|
|
{
|
|
|
|
m_fScaleY = newScaleY;
|
|
|
|
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
|
|
|
#ifdef CCX_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
|
|
|
m_bIsTransformGLDirty = true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/// position getter
|
|
|
|
CGPoint CCNode::getPosition()
|
|
|
|
{
|
|
|
|
return m_tPosition;
|
|
|
|
}
|
2010-07-07 15:24:44 +08:00
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// position setter
|
|
|
|
void CCNode::setPosition(CGPoint newPosition)
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2010-07-12 17:56:06 +08:00
|
|
|
m_tPosition = newPosition;
|
|
|
|
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
|
|
|
#ifdef CCX_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
|
|
|
m_bIsTransformGLDirty = true;
|
|
|
|
#endif
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// children getter
|
|
|
|
NSMutableArray * CCNode::getChildren()
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2010-07-12 17:56:06 +08:00
|
|
|
return m_pChildren;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// children getter
|
|
|
|
// camera: lazy alloc
|
|
|
|
CCCamera* getCamera()
|
|
|
|
{
|
|
|
|
/** @todo no declare in class
|
|
|
|
if( ! camera_ ) {
|
|
|
|
camera_ = [[CCCamera alloc] init];
|
|
|
|
|
|
|
|
// by default, center camera at the Sprite's anchor point
|
|
|
|
// [camera_ setCenterX:anchorPointInPixels_.x centerY:anchorPointInPixels_.y centerZ:0];
|
|
|
|
// [camera_ setEyeX:anchorPointInPixels_.x eyeY:anchorPointInPixels_.y eyeZ:1];
|
|
|
|
|
|
|
|
// [camera_ setCenterX:0 centerY:0 centerZ:0];
|
|
|
|
// [camera_ setEyeX:0 eyeY:0 eyeZ:1];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return camera_;*/
|
|
|
|
return NULL;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
2010-07-12 17:56:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
/// grid getter
|
2010-07-09 18:24:08 +08:00
|
|
|
/// @todo
|
2010-07-07 15:24:44 +08:00
|
|
|
//CCGridBase* CCNode::getGrid()
|
|
|
|
//{
|
|
|
|
// return m_pGrid;
|
|
|
|
//}
|
2010-07-12 17:56:06 +08:00
|
|
|
|
|
|
|
/// grid setter
|
2010-07-09 18:24:08 +08:00
|
|
|
/// @todo
|
2010-07-07 15:24:44 +08:00
|
|
|
//void CCNode::setGrid(CCGridBase* pGrid)
|
|
|
|
//{
|
|
|
|
// if(/*!pGrid &&*/ m_pGrid)
|
|
|
|
// m_pGrid->release();
|
|
|
|
//
|
|
|
|
// m_pGrid = pGrid;
|
|
|
|
//
|
|
|
|
// if(m_pGrid)
|
|
|
|
// m_pGrid->retain();
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
CGPoint CCNode::getAnchorPoint()
|
2010-07-07 15:24:44 +08:00
|
|
|
{
|
2010-07-12 17:56:06 +08:00
|
|
|
return m_tAnchorPoint;
|
2010-07-07 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// @todo anchorPoint setter
|
2010-07-08 10:26:58 +08:00
|
|
|
void CCNode::setAnchorPoint(CGPoint point)
|
|
|
|
{
|
|
|
|
/*if( ! CGPointEqualToPoint(point, m_anchorPoint) )
|
|
|
|
{
|
2010-07-12 17:56:06 +08:00
|
|
|
m_anchorPoint = point;
|
|
|
|
this->m_anchorPointInPixels = ccp( m_contentSize.width * m_anchorPoint.x, m_contentSize.height * m_anchorPoint.y );
|
|
|
|
m_isTransformDirty = m_isInverseDirty = true;
|
|
|
|
#ifdef CCX_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
|
|
|
m_bIsTransformGLDirty = true;
|
|
|
|
#endif
|
2010-07-08 10:26:58 +08:00
|
|
|
}*/
|
2010-07-12 17:56:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// anchorPointInPixels getter
|
|
|
|
CGPoint 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
|
|
|
|
CGSize CCNode::getContentSize()
|
|
|
|
{
|
|
|
|
return m_tContentSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @todo contentSize setter
|
2010-07-07 15:24:44 +08:00
|
|
|
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
|
|
|
//}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
/// isRunning getter
|
|
|
|
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;
|
|
|
|
#ifdef CCX_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
|
|
|
m_bIsTransformGLDirty = true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/// tag getter
|
|
|
|
int CCNode::getTag()
|
|
|
|
{
|
|
|
|
return m_iTag;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// tag setter
|
|
|
|
void CCNode::setTag(int var)
|
|
|
|
{
|
|
|
|
m_iTag = var;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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-07-12 17:56:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// @todo
|
|
|
|
//CGRect CCNode::boundingBox()
|
|
|
|
//{
|
|
|
|
// CGRect rect = CGRectMake(0, 0, m_contentSize.width, m_contentSize.height);
|
|
|
|
// return CGRectApplyAffineTransform(rect, nodeToParentTransform());
|
|
|
|
//}
|
2010-07-07 15:24:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-07-09 18:24:08 +08:00
|
|
|
|
|
|
|
/** @todo
|
|
|
|
#if CC_COCOSNODE_RENDER_SUBPIXEL
|
|
|
|
#define RENDER_IN_SUBPIXEL
|
|
|
|
#else
|
|
|
|
#define RENDER_IN_SUBPIXEL (int)
|
|
|
|
#endif
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CCNode * CCNode::node(void)
|
|
|
|
{
|
|
|
|
/// @todo return [[[self alloc] init] autorelease];
|
2010-07-12 17:56:06 +08:00
|
|
|
CCNode * pNode = new CCNode();
|
|
|
|
pNode->autorelease();
|
|
|
|
return pNode;
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::cleanup()
|
|
|
|
{
|
|
|
|
/** @todo
|
|
|
|
// actions
|
|
|
|
[self stopAllActions];
|
|
|
|
[self unscheduleAllSelectors];
|
|
|
|
|
|
|
|
// timers
|
|
|
|
|
|
|
|
[children_ makeObjectsPerformSelector:@selector(cleanup)];*/
|
|
|
|
}
|
|
|
|
/** @todo no declare in class
|
|
|
|
- (NSString*) description
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat:@"<%@ = %08X | Tag = %i>", [self class], self, tag_];
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
/** @todo no declare in class
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
CCLOGINFO( @"cocos2d: deallocing %@", self);
|
|
|
|
|
|
|
|
// attributes
|
|
|
|
[camera_ release];
|
|
|
|
|
|
|
|
[grid_ release];
|
|
|
|
|
|
|
|
// children
|
|
|
|
|
|
|
|
for (CCNode *child in children_) {
|
|
|
|
child.parent = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
[children_ release];
|
|
|
|
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
// lazy allocs
|
|
|
|
void CCNode::childrenAlloc(void)
|
|
|
|
{
|
|
|
|
/// @todo children_ = [[CCArray alloc] initWithCapacity:4];
|
|
|
|
}
|
|
|
|
|
|
|
|
CCNode* CCNode::getChildByTag(int aTag)
|
|
|
|
{
|
|
|
|
/** @todo
|
|
|
|
NSAssert( aTag != kCCNodeTagInvalid, @"Invalid tag");
|
|
|
|
|
|
|
|
for( CCNode *node in children_ ) {
|
|
|
|
if( node.tag == aTag )
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
// not found
|
|
|
|
return nil;*/
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
CCNode * CCNode::addChild(CCNode *node, int zOrder, int tag)
|
|
|
|
{
|
|
|
|
/** @todo
|
|
|
|
NSAssert( child != nil, @"Argument must be non-nil");
|
|
|
|
NSAssert( child.parent == nil, @"child already added. It can't be added again");
|
|
|
|
|
|
|
|
if( ! children_ )
|
|
|
|
[self childrenAlloc];
|
|
|
|
|
|
|
|
[self insertChild:child z:z];
|
|
|
|
|
|
|
|
child.tag = aTag;
|
|
|
|
|
|
|
|
[child setParent: self];
|
|
|
|
|
|
|
|
if( isRunning_ )
|
|
|
|
[child onEnter];
|
|
|
|
return self;*/
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCNode * CCNode::addChild(CCNode *node, int zOrder)
|
|
|
|
{
|
|
|
|
/** @todo
|
|
|
|
NSAssert( child != nil, @"Argument must be non-nil");
|
|
|
|
return [self addChild:child z:z tag:child.tag];*/
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCNode * CCNode::addChild(CCNode *node)
|
|
|
|
{
|
|
|
|
/** @todo
|
|
|
|
NSAssert( child != nil, @"Argument must be non-nil");
|
|
|
|
return [self addChild:child z:child.zOrder tag:child.tag];*/
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::removeFromParentAndCleanup(bool cleanup)
|
|
|
|
{
|
|
|
|
/** @todo
|
|
|
|
[self.parent removeChild:self cleanup:cleanup];*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/* "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
|
|
|
|
*/
|
|
|
|
void CCNode::removeChild(CCNode* node, bool cleanup)
|
|
|
|
{
|
|
|
|
/** @todo
|
|
|
|
// explicit nil handling
|
|
|
|
if (child == nil)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( [children_ containsObject:child] )
|
|
|
|
[self detachChild:child cleanup:cleanup];*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::removeChildByTag(int tag, bool cleanup)
|
|
|
|
{
|
|
|
|
/** @todo
|
|
|
|
NSAssert( aTag != kCCNodeTagInvalid, @"Invalid tag");
|
|
|
|
|
|
|
|
CCNode *child = [self getChildByTag:aTag];
|
|
|
|
|
|
|
|
if (child == nil)
|
|
|
|
CCLOG(@"cocos2d: removeChildByTag: child not found!");
|
|
|
|
else
|
|
|
|
[self removeChild:child cleanup:cleanup];*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::removeAllChildrenWithCleanup(bool cleanup)
|
|
|
|
{
|
|
|
|
/** @todo
|
|
|
|
// not using detachChild improves speed here
|
|
|
|
for (CCNode *c in children_)
|
|
|
|
{
|
|
|
|
// IMPORTANT:
|
|
|
|
// -1st do onExit
|
|
|
|
// -2nd cleanup
|
|
|
|
if (isRunning_)
|
|
|
|
[c onExit];
|
|
|
|
|
|
|
|
if (cleanup)
|
|
|
|
[c cleanup];
|
|
|
|
|
|
|
|
// set parent nil at the end (issue #476)
|
|
|
|
[c setParent:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
[children_ removeAllObjects];*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::detachChild(CCNode *child, bool doCleanup)
|
|
|
|
{
|
|
|
|
/** @todo
|
|
|
|
// IMPORTANT:
|
|
|
|
// -1st do onExit
|
|
|
|
// -2nd cleanup
|
|
|
|
if (isRunning_)
|
|
|
|
[child onExit];
|
|
|
|
|
|
|
|
// 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];
|
|
|
|
|
|
|
|
// set parent nil at the end (issue #476)
|
|
|
|
[child setParent:nil];
|
|
|
|
|
|
|
|
[children_ removeObject:child];*/
|
|
|
|
}
|
|
|
|
|
|
|
|
// used internally to alter the zOrder variable. DON'T call this method manually
|
|
|
|
void CCNode::setZOrder(int z)
|
|
|
|
{
|
|
|
|
m_iZOrder = z;
|
|
|
|
}
|
|
|
|
|
|
|
|
// helper used by reorderChild & add
|
|
|
|
void CCNode::insertChild(CCNode* child, int z)
|
|
|
|
{
|
|
|
|
/** @todo
|
|
|
|
int index=0;
|
|
|
|
BOOL added = NO;
|
|
|
|
for( CCNode *a in children_ ) {
|
|
|
|
if ( a.zOrder > z ) {
|
|
|
|
added = YES;
|
|
|
|
[ children_ insertObject:child atIndex:index];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ! added )
|
|
|
|
[children_ addObject:child];
|
|
|
|
|
|
|
|
[child _setZOrder:z];*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::reorderChild(CCNode *child, int zOrder)
|
|
|
|
{
|
|
|
|
/** @todo
|
|
|
|
NSAssert( child != nil, @"Child must be non-nil");
|
|
|
|
|
|
|
|
[child retain];
|
|
|
|
[children_ removeObject:child];
|
|
|
|
|
|
|
|
[self insertChild:child z:z];
|
|
|
|
|
|
|
|
[child release];*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::draw()
|
|
|
|
{
|
|
|
|
// override me
|
|
|
|
// Only use this function to draw your staff.
|
|
|
|
// DON'T draw your stuff outside this method
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::visit()
|
|
|
|
{
|
|
|
|
/** @todo
|
|
|
|
if (!visible_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
glPushMatrix();
|
|
|
|
|
|
|
|
if ( grid_ && grid_.active) {
|
|
|
|
[grid_ beforeDraw];
|
|
|
|
[self transformAncestors];
|
|
|
|
}
|
|
|
|
|
|
|
|
[self transform];
|
|
|
|
|
|
|
|
ccArray *arrayData;
|
|
|
|
int i = 0, nu;
|
|
|
|
if(children_){
|
|
|
|
arrayData = children_->data;
|
|
|
|
nu = arrayData->num;
|
|
|
|
for(;i<nu; i++){
|
|
|
|
CCNode *child = arrayData->arr[i];
|
|
|
|
if ( child.zOrder < 0 )
|
|
|
|
[child visit];
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[self draw];
|
|
|
|
|
|
|
|
if(children_)
|
|
|
|
for (;i<nu; i++)
|
|
|
|
[arrayData->arr[i] visit];
|
|
|
|
|
|
|
|
|
|
|
|
if ( grid_ && grid_.active)
|
|
|
|
[grid_ afterDraw:self];
|
|
|
|
|
|
|
|
glPopMatrix();*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::transformAncestors()
|
|
|
|
{
|
|
|
|
if( m_pParent != NULL )
|
|
|
|
{
|
|
|
|
m_pParent->transformAncestors();
|
|
|
|
m_pParent->transform();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::transform()
|
|
|
|
{
|
|
|
|
/** @todo
|
|
|
|
// transformations
|
|
|
|
|
|
|
|
#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
|
|
|
// BEGIN alternative -- using cached transform
|
|
|
|
//
|
|
|
|
if( isTransformGLDirty_ ) {
|
|
|
|
CGAffineTransform t = [self nodeToParentTransform];
|
|
|
|
CGAffineToGL(&t, transformGL_);
|
|
|
|
isTransformGLDirty_ = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
glMultMatrixf(transformGL_);
|
|
|
|
if( vertexZ_ )
|
|
|
|
glTranslatef(0, 0, vertexZ_);
|
|
|
|
|
|
|
|
// XXX: Expensive calls. Camera should be integrated into the cached affine matrix
|
|
|
|
if ( camera_ && !(grid_ && grid_.active) ) {
|
|
|
|
BOOL translate = (anchorPointInPixels_.x != 0.0f || anchorPointInPixels_.y != 0.0f);
|
|
|
|
|
|
|
|
if( translate )
|
|
|
|
glTranslatef(RENDER_IN_SUBPIXEL(anchorPointInPixels_.x), RENDER_IN_SUBPIXEL(anchorPointInPixels_.y), 0);
|
|
|
|
|
|
|
|
[camera_ locate];
|
|
|
|
|
|
|
|
if( translate )
|
|
|
|
glTranslatef(RENDER_IN_SUBPIXEL(-anchorPointInPixels_.x), RENDER_IN_SUBPIXEL(-anchorPointInPixels_.y), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// END alternative
|
|
|
|
|
|
|
|
#else
|
|
|
|
// BEGIN original implementation
|
|
|
|
//
|
|
|
|
// translate
|
|
|
|
if ( isRelativeAnchorPoint_ && (anchorPointInPixels_.x != 0 || anchorPointInPixels_.y != 0 ) )
|
|
|
|
glTranslatef( RENDER_IN_SUBPIXEL(-anchorPointInPixels_.x), RENDER_IN_SUBPIXEL(-anchorPointInPixels_.y), 0);
|
|
|
|
|
|
|
|
if (anchorPointInPixels_.x != 0 || anchorPointInPixels_.y != 0)
|
|
|
|
glTranslatef( RENDER_IN_SUBPIXEL(position_.x + anchorPointInPixels_.x), RENDER_IN_SUBPIXEL(position_.y + anchorPointInPixels_.y), vertexZ_);
|
|
|
|
else if ( position_.x !=0 || position_.y !=0 || vertexZ_ != 0)
|
|
|
|
glTranslatef( RENDER_IN_SUBPIXEL(position_.x), RENDER_IN_SUBPIXEL(position_.y), vertexZ_ );
|
|
|
|
|
|
|
|
// rotate
|
|
|
|
if (rotation_ != 0.0f )
|
|
|
|
glRotatef( -rotation_, 0.0f, 0.0f, 1.0f );
|
|
|
|
|
|
|
|
// scale
|
|
|
|
if (scaleX_ != 1.0f || scaleY_ != 1.0f)
|
|
|
|
glScalef( scaleX_, scaleY_, 1.0f );
|
|
|
|
|
|
|
|
if ( camera_ && !(grid_ && grid_.active) )
|
|
|
|
[camera_ locate];
|
|
|
|
|
|
|
|
// restore and re-position point
|
|
|
|
if (anchorPointInPixels_.x != 0.0f || anchorPointInPixels_.y != 0.0f)
|
|
|
|
glTranslatef(RENDER_IN_SUBPIXEL(-anchorPointInPixels_.x), RENDER_IN_SUBPIXEL(-anchorPointInPixels_.y), 0);
|
|
|
|
|
|
|
|
//
|
|
|
|
// END original implementation
|
|
|
|
#endif
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCNode::onEnter()
|
|
|
|
{
|
|
|
|
/** @todo callback?
|
|
|
|
[children_ makeObjectsPerformSelector:@selector(onEnter)];
|
|
|
|
|
|
|
|
[self resumeSchedulerAndActions];
|
|
|
|
|
|
|
|
isRunning_ = YES;*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::onEnterTransitionDidFinish()
|
|
|
|
{
|
|
|
|
/** @todo callback?
|
|
|
|
[children_ makeObjectsPerformSelector:@selector(onEnterTransitionDidFinish)];*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::onExit()
|
|
|
|
{
|
|
|
|
/** @todo callback?
|
|
|
|
[self pauseSchedulerAndActions];
|
|
|
|
|
|
|
|
isRunning_ = NO;
|
|
|
|
|
|
|
|
[children_ makeObjectsPerformSelector:@selector(onExit)];*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @todo
|
|
|
|
-(CCAction*) runAction:(CCAction*) action
|
|
|
|
{
|
|
|
|
NSAssert( action != nil, @"Argument must be non-nil");
|
|
|
|
|
|
|
|
[[CCActionManager sharedManager] addAction:action target:self paused:!isRunning_];
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
void CCNode::stopAllActions()
|
|
|
|
{
|
|
|
|
/** @todo
|
|
|
|
[[CCActionManager sharedManager] removeAllActionsFromTarget:self];*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @todo
|
|
|
|
-(void) stopAction: (CCAction*) action
|
|
|
|
{
|
|
|
|
[[CCActionManager sharedManager] removeAction:action];
|
|
|
|
}*/
|
|
|
|
|
|
|
|
void CCNode::stopActionByTag(int tag)
|
|
|
|
{
|
|
|
|
/** @todo
|
|
|
|
NSAssert( aTag != kCCActionTagInvalid, @"Invalid tag");
|
|
|
|
[[CCActionManager sharedManager] removeActionByTag:aTag target:self];*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @todo
|
|
|
|
-(CCAction*) getActionByTag:(int) aTag
|
|
|
|
{
|
|
|
|
NSAssert( aTag != kCCActionTagInvalid, @"Invalid tag");
|
|
|
|
|
|
|
|
return [[CCActionManager sharedManager] getActionByTag:aTag target:self];
|
|
|
|
}*/
|
|
|
|
|
|
|
|
int CCNode::numberOfRunningActions()
|
|
|
|
{
|
|
|
|
/// @todo return [[CCActionManager sharedManager] numberOfRunningActionsInTarget:self];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// @todo #pragma mark CCNode - Callbacks????
|
|
|
|
|
|
|
|
void CCNode::scheduleUpdate()
|
|
|
|
{
|
|
|
|
scheduleUpdateWithPriority(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::scheduleUpdateWithPriority(int priority)
|
|
|
|
{
|
|
|
|
/// @todo [[CCScheduler sharedScheduler] scheduleUpdateForTarget:self priority:priority paused:!isRunning_];
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::unscheduleUpdate()
|
|
|
|
{
|
|
|
|
/// @todo [[CCScheduler sharedScheduler] unscheduleUpdateForTarget:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @todo
|
|
|
|
-(void) schedule:(SEL)selector
|
|
|
|
{
|
|
|
|
[self schedule:selector interval:0];
|
|
|
|
}*/
|
|
|
|
|
|
|
|
/** @todo
|
|
|
|
-(void) schedule:(SEL)selector interval:(ccTime)interval
|
|
|
|
{
|
|
|
|
NSAssert( selector != nil, @"Argument must be non-nil");
|
|
|
|
NSAssert( interval >=0, @"Arguemnt must be positive");
|
|
|
|
|
|
|
|
[[CCScheduler sharedScheduler] scheduleSelector:selector forTarget:self interval:interval paused:!isRunning_];
|
|
|
|
}*/
|
|
|
|
|
|
|
|
/** @todo
|
|
|
|
-(void) unschedule:(SEL)selector
|
|
|
|
{
|
|
|
|
// explicit nil handling
|
|
|
|
if (selector == nil)
|
|
|
|
return;
|
|
|
|
|
|
|
|
[[CCScheduler sharedScheduler] unscheduleSelector:selector forTarget:self];
|
|
|
|
}*/
|
|
|
|
|
|
|
|
void CCNode::unscheduleAllSelectors()
|
|
|
|
{
|
|
|
|
/// @todo [[CCScheduler sharedScheduler] unscheduleAllSelectorsForTarget:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::resumeSchedulerAndActions()
|
|
|
|
{
|
|
|
|
/** @todo
|
|
|
|
[[CCScheduler sharedScheduler] resumeTarget:self];
|
|
|
|
[[CCActionManager sharedManager] resumeTarget:self];*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::pauseSchedulerAndActions()
|
|
|
|
{
|
|
|
|
/** @todo
|
|
|
|
[[CCScheduler sharedScheduler] pauseTarget:self];
|
|
|
|
[[CCActionManager sharedManager] pauseTarget:self];*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @todo
|
2010-07-12 17:56:06 +08:00
|
|
|
CGAffineTransform CCNode::nodeToParentTransform(void)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
|
|
|
if ( isTransformDirty_ ) {
|
|
|
|
|
|
|
|
transform_ = CGAffineTransformIdentity;
|
|
|
|
|
|
|
|
if ( !isRelativeAnchorPoint_ && !CGPointEqualToPoint(anchorPointInPixels_, CGPointZero) )
|
|
|
|
transform_ = CGAffineTransformTranslate(transform_, anchorPointInPixels_.x, anchorPointInPixels_.y);
|
|
|
|
|
|
|
|
if( ! CGPointEqualToPoint(position_, CGPointZero) )
|
|
|
|
transform_ = CGAffineTransformTranslate(transform_, position_.x, position_.y);
|
|
|
|
if( rotation_ != 0 )
|
|
|
|
transform_ = CGAffineTransformRotate(transform_, -CC_DEGREES_TO_RADIANS(rotation_));
|
|
|
|
if( ! (scaleX_ == 1 && scaleY_ == 1) )
|
|
|
|
transform_ = CGAffineTransformScale(transform_, scaleX_, scaleY_);
|
|
|
|
|
|
|
|
if( ! CGPointEqualToPoint(anchorPointInPixels_, CGPointZero) )
|
|
|
|
transform_ = CGAffineTransformTranslate(transform_, -anchorPointInPixels_.x, -anchorPointInPixels_.y);
|
|
|
|
|
|
|
|
isTransformDirty_ = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return transform_;
|
2010-07-12 17:56:06 +08:00
|
|
|
}*/
|
|
|
|
/** @todo
|
2010-07-09 18:24:08 +08:00
|
|
|
- (CGAffineTransform)parentToNodeTransform
|
|
|
|
{
|
|
|
|
if ( isInverseDirty_ ) {
|
|
|
|
inverse_ = CGAffineTransformInvert([self nodeToParentTransform]);
|
|
|
|
isInverseDirty_ = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return inverse_;
|
2010-07-12 17:56:06 +08:00
|
|
|
}*/
|
|
|
|
/** @todo
|
2010-07-09 18:24:08 +08:00
|
|
|
- (CGAffineTransform)nodeToWorldTransform
|
|
|
|
{
|
|
|
|
CGAffineTransform t = [self nodeToParentTransform];
|
|
|
|
|
|
|
|
for (CCNode *p = parent_; p != nil; p = p.parent)
|
|
|
|
t = CGAffineTransformConcat(t, [p nodeToParentTransform]);
|
|
|
|
|
|
|
|
return t;
|
2010-07-12 17:56:06 +08:00
|
|
|
}*/
|
|
|
|
/** @todo
|
2010-07-09 18:24:08 +08:00
|
|
|
- (CGAffineTransform)worldToNodeTransform
|
|
|
|
{
|
|
|
|
return CGAffineTransformInvert([self nodeToWorldTransform]);
|
2010-07-12 17:56:06 +08:00
|
|
|
}*/
|
2010-07-09 18:24:08 +08:00
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
CGPoint CCNode::convertToNodeSpace(CGPoint worldPoint)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2010-07-12 17:56:06 +08:00
|
|
|
/// @todo return CGPointApplyAffineTransform(worldPoint, [self worldToNodeTransform]);
|
|
|
|
return CGPoint(0,0);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
CGPoint CCNode::convertToWorldSpace(CGPoint nodePoint)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2010-07-12 17:56:06 +08:00
|
|
|
/// @todo return CGPointApplyAffineTransform(nodePoint, [self nodeToWorldTransform]);
|
|
|
|
return CGPoint(0,0);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
CGPoint CCNode::convertToNodeSpaceAR(CGPoint worldPoint)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2010-07-12 17:56:06 +08:00
|
|
|
/** @todo
|
2010-07-09 18:24:08 +08:00
|
|
|
CGPoint nodePoint = [self convertToNodeSpace:worldPoint];
|
2010-07-12 17:56:06 +08:00
|
|
|
return ccpSub(nodePoint, anchorPointInPixels_);*/
|
|
|
|
return CGPoint(0,0);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
|
|
|
|
2010-07-12 17:56:06 +08:00
|
|
|
CGPoint CCNode::convertToWorldSpaceAR(CGPoint nodePoint)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2010-07-12 17:56:06 +08:00
|
|
|
/** @todo
|
2010-07-09 18:24:08 +08:00
|
|
|
nodePoint = ccpAdd(nodePoint, anchorPointInPixels_);
|
2010-07-12 17:56:06 +08:00
|
|
|
return [self convertToWorldSpace:nodePoint];*/
|
|
|
|
return CGPoint(0,0);
|
2010-07-09 18:24:08 +08:00
|
|
|
}
|
2010-07-12 17:56:06 +08:00
|
|
|
/** @todo no declare in .h file
|
|
|
|
CGPoint CCNode::convertToWindowSpace(CGPoint nodePoint)
|
2010-07-09 18:24:08 +08:00
|
|
|
{
|
2010-07-12 17:56:06 +08:00
|
|
|
|
2010-07-09 18:24:08 +08:00
|
|
|
CGPoint worldPoint = [self convertToWorldSpace:nodePoint];
|
|
|
|
return [[CCDirector sharedDirector] convertToUI:worldPoint];
|
2010-07-12 17:56:06 +08:00
|
|
|
}*/
|
2010-07-09 18:24:08 +08:00
|
|
|
|
|
|
|
// convenience methods which take a UITouch instead of CGPoint
|
2010-07-12 17:56:06 +08:00
|
|
|
/** @todo
|
2010-07-09 18:24:08 +08:00
|
|
|
- (CGPoint)convertTouchToNodeSpace:(UITouch *)touch
|
|
|
|
{
|
|
|
|
CGPoint point = [touch locationInView: [touch view]];
|
|
|
|
point = [[CCDirector sharedDirector] convertToGL: point];
|
|
|
|
return [self convertToNodeSpace:point];
|
2010-07-12 17:56:06 +08:00
|
|
|
}*/
|
|
|
|
/** @todo
|
2010-07-09 18:24:08 +08:00
|
|
|
- (CGPoint)convertTouchToNodeSpaceAR:(UITouch *)touch
|
|
|
|
{
|
|
|
|
CGPoint point = [touch locationInView: [touch view]];
|
|
|
|
point = [[CCDirector sharedDirector] convertToGL: point];
|
|
|
|
return [self convertToNodeSpaceAR:point];
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|