mirror of https://github.com/axmolengine/axmol.git
Merge branch 'upto-0.99.5' of https://github.com/cocos2d/cocos2d-x into merge
This commit is contained in:
commit
969e65b959
|
@ -22,9 +22,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CCNODE_H__
|
||||
#define __CCNODE_H__
|
||||
#ifndef __PLATFOMR_CCNODE_H__
|
||||
#define __PLATFOMR_CCNODE_H__
|
||||
|
||||
#include "config_platform.h"
|
||||
#include "CCXCocos2dDefine.h"
|
||||
#include "ccMacros.h"
|
||||
#include "CGAffineTransform.h"
|
||||
|
@ -33,485 +34,504 @@ THE SOFTWARE.
|
|||
#include "ccxCommon.h"
|
||||
#include "selector_protocol.h"
|
||||
|
||||
#include <GLES/gl.h>
|
||||
#include "CCGL.h"
|
||||
|
||||
namespace cocos2d {
|
||||
class CCCamera;
|
||||
class CCGridBase;
|
||||
class CGPoint;
|
||||
class CCTouch;
|
||||
class CCAction;
|
||||
class CCRGBAProtocol;
|
||||
class CCLabelProtocol;
|
||||
class CCCamera;
|
||||
class CCGridBase;
|
||||
class CGPoint;
|
||||
class CCTouch;
|
||||
class CCAction;
|
||||
class CCRGBAProtocol;
|
||||
class CCLabelProtocol;
|
||||
|
||||
enum {
|
||||
kCCNodeTagInvalid = -1,
|
||||
};
|
||||
enum {
|
||||
kCCNodeTagInvalid = -1,
|
||||
};
|
||||
|
||||
/** @brief CCNode is the main element. Anything thats gets drawn or contains things that get drawn is a CCNode.
|
||||
The most popular CCNodes are: CCScene, CCLayer, CCSprite, CCMenu.
|
||||
/** @brief CCNode is the main element. Anything thats gets drawn or contains things that get drawn is a CCNode.
|
||||
The most popular CCNodes are: CCScene, CCLayer, CCSprite, CCMenu.
|
||||
|
||||
The main features of a CCNode are:
|
||||
- They can contain other CCNode nodes (addChild, getChildByTag, removeChild, etc)
|
||||
- They can schedule periodic callback (schedule, unschedule, etc)
|
||||
- They can execute actions (runAction, stopAction, etc)
|
||||
The main features of a CCNode are:
|
||||
- They can contain other CCNode nodes (addChild, getChildByTag, removeChild, etc)
|
||||
- They can schedule periodic callback (schedule, unschedule, etc)
|
||||
- They can execute actions (runAction, stopAction, etc)
|
||||
|
||||
Some CCNode nodes provide extra functionality for them or their children.
|
||||
Some CCNode nodes provide extra functionality for them or their children.
|
||||
|
||||
Subclassing a CCNode usually means (one/all) of:
|
||||
- overriding init to initialize resources and schedule callbacks
|
||||
- create callbacks to handle the advancement of time
|
||||
- overriding draw to render the node
|
||||
Subclassing a CCNode usually means (one/all) of:
|
||||
- overriding init to initialize resources and schedule callbacks
|
||||
- create callbacks to handle the advancement of time
|
||||
- overriding draw to render the node
|
||||
|
||||
Features of CCNode:
|
||||
- position
|
||||
- scale (x, y)
|
||||
- rotation (in degrees, clockwise)
|
||||
- CCCamera (an interface to gluLookAt )
|
||||
- CCGridBase (to do mesh transformations)
|
||||
- anchor point
|
||||
- size
|
||||
- visible
|
||||
- z-order
|
||||
- openGL z position
|
||||
Features of CCNode:
|
||||
- position
|
||||
- scale (x, y)
|
||||
- rotation (in degrees, clockwise)
|
||||
- CCCamera (an interface to gluLookAt )
|
||||
- CCGridBase (to do mesh transformations)
|
||||
- anchor point
|
||||
- size
|
||||
- visible
|
||||
- z-order
|
||||
- openGL z position
|
||||
|
||||
Default values:
|
||||
- rotation: 0
|
||||
- position: (x=0,y=0)
|
||||
- scale: (x=1,y=1)
|
||||
- contentSize: (x=0,y=0)
|
||||
- anchorPoint: (x=0,y=0)
|
||||
Default values:
|
||||
- rotation: 0
|
||||
- position: (x=0,y=0)
|
||||
- scale: (x=1,y=1)
|
||||
- contentSize: (x=0,y=0)
|
||||
- anchorPoint: (x=0,y=0)
|
||||
|
||||
Limitations:
|
||||
- A CCNode is a "void" object. It doesn't have a texture
|
||||
Limitations:
|
||||
- A CCNode is a "void" object. It doesn't have a texture
|
||||
|
||||
Order in transformations with grid disabled
|
||||
-# The node will be translated (position)
|
||||
-# The node will be rotated (rotation)
|
||||
-# The node will be scaled (scale)
|
||||
-# The node will be moved according to the camera values (camera)
|
||||
Order in transformations with grid disabled
|
||||
-# The node will be translated (position)
|
||||
-# The node will be rotated (rotation)
|
||||
-# The node will be scaled (scale)
|
||||
-# The node will be moved according to the camera values (camera)
|
||||
|
||||
Order in transformations with grid enabled
|
||||
-# The node will be translated (position)
|
||||
-# The node will be rotated (rotation)
|
||||
-# The node will be scaled (scale)
|
||||
-# The grid will capture the screen
|
||||
-# The node will be moved according to the camera values (camera)
|
||||
-# The grid will render the captured screen
|
||||
Order in transformations with grid enabled
|
||||
-# The node will be translated (position)
|
||||
-# The node will be rotated (rotation)
|
||||
-# The node will be scaled (scale)
|
||||
-# The grid will capture the screen
|
||||
-# The node will be moved according to the camera values (camera)
|
||||
-# The grid will render the captured screen
|
||||
|
||||
Camera:
|
||||
- Each node has a camera. By default it points to the center of the CCNode.
|
||||
*/
|
||||
Camera:
|
||||
- Each node has a camera. By default it points to the center of the CCNode.
|
||||
*/
|
||||
|
||||
class CCX_DLL CCNode : public SelectorProtocol, public NSObject
|
||||
{
|
||||
class CCX_DLL CCNode : public SelectorProtocol, public NSObject
|
||||
{
|
||||
|
||||
// variable property
|
||||
// variable property
|
||||
|
||||
/** The z order of the node relative to it's "brothers": children of the same parent */
|
||||
CCX_PROPERTY_READONLY(int, m_nZOrder, ZOrder)
|
||||
/** The z order of the node relative to it's "brothers": children of the same parent */
|
||||
CCX_PROPERTY_READONLY(int, m_nZOrder, ZOrder)
|
||||
|
||||
/** The real openGL Z vertex.
|
||||
Differences between openGL Z vertex and cocos2d Z order:
|
||||
- OpenGL Z modifies the Z vertex, and not the Z order in the relation between parent-children
|
||||
- OpenGL Z might require to set 2D projection
|
||||
- cocos2d Z order works OK if all the nodes uses the same openGL Z vertex. eg: vertexZ = 0
|
||||
@warning: Use it at your own risk since it might break the cocos2d parent-children z order
|
||||
@since v0.8
|
||||
*/
|
||||
CCX_PROPERTY(float, m_fVertexZ, VertexZ)
|
||||
/** The real openGL Z vertex.
|
||||
Differences between openGL Z vertex and cocos2d Z order:
|
||||
- OpenGL Z modifies the Z vertex, and not the Z order in the relation between parent-children
|
||||
- OpenGL Z might require to set 2D projection
|
||||
- cocos2d Z order works OK if all the nodes uses the same openGL Z vertex. eg: vertexZ = 0
|
||||
@warning: Use it at your own risk since it might break the cocos2d parent-children z order
|
||||
@since v0.8
|
||||
*/
|
||||
CCX_PROPERTY(float, m_fVertexZ, VertexZ)
|
||||
|
||||
/** The rotation (angle) of the node in degrees. 0 is the default rotation angle. Positive values rotate node CW. */
|
||||
CCX_PROPERTY(float, m_fRotation, Rotation)
|
||||
/** The rotation (angle) of the node in degrees. 0 is the default rotation angle. Positive values rotate node CW. */
|
||||
CCX_PROPERTY(float, m_fRotation, Rotation)
|
||||
|
||||
/** Get the scale factor of the node.
|
||||
@warning: Assert when m_fScaleX != m_fScaleY.
|
||||
*/
|
||||
float getScale();
|
||||
/** The scale factor of the node. 1.0 is the default scale factor. It modifies the X and Y scale at the same time. */
|
||||
void setScale(float scale);
|
||||
/** Get the scale factor of the node.
|
||||
@warning: Assert when m_fScaleX != m_fScaleY.
|
||||
*/
|
||||
float getScale();
|
||||
/** The scale factor of the node. 1.0 is the default scale factor. It modifies the X and Y scale at the same time. */
|
||||
void setScale(float scale);
|
||||
|
||||
/** The scale factor of the node. 1.0 is the default scale factor. It only modifies the X scale factor. */
|
||||
CCX_PROPERTY(float, m_fScaleX, ScaleX)
|
||||
/** The scale factor of the node. 1.0 is the default scale factor. It only modifies the X scale factor. */
|
||||
CCX_PROPERTY(float, m_fScaleX, ScaleX)
|
||||
|
||||
/** The scale factor of the node. 1.0 is the default scale factor. It only modifies the Y scale factor. */
|
||||
CCX_PROPERTY(float, m_fScaleY, ScaleY)
|
||||
/** The scale factor of the node. 1.0 is the default scale factor. It only modifies the Y scale factor. */
|
||||
CCX_PROPERTY(float, m_fScaleY, ScaleY)
|
||||
|
||||
/** Position (x,y) of the node in OpenGL coordinates. (0,0) is the left-bottom corner. */
|
||||
CCX_PROPERTY(CGPoint, m_tPosition, Position)
|
||||
/** Position (x,y) of the node in OpenGL coordinates. (0,0) is the left-bottom corner. */
|
||||
CCX_PROPERTY(CGPoint, m_tPosition, Position)
|
||||
CCX_PROPERTY(CGPoint, m_tPositionInPixels, PositionInPixels)
|
||||
|
||||
CCX_PROPERTY_READONLY(NSMutableArray<CCNode *> *, m_pChildren, Children)
|
||||
CCX_PROPERTY_READONLY(NSMutableArray<CCNode *> *, m_pChildren, Children)
|
||||
|
||||
/** A CCCamera object that lets you move the node using a gluLookAt
|
||||
*/
|
||||
CCX_PROPERTY_READONLY(CCCamera *, m_pCamera, Camera)
|
||||
/** A CCCamera object that lets you move the node using a gluLookAt
|
||||
*/
|
||||
CCX_PROPERTY_READONLY(CCCamera *, m_pCamera, Camera)
|
||||
|
||||
/** A CCGrid object that is used when applying effects */
|
||||
CCX_PROPERTY(CCGridBase *, m_pGrid, Grid)
|
||||
/** A CCGrid object that is used when applying effects */
|
||||
CCX_PROPERTY(CCGridBase *, m_pGrid, Grid)
|
||||
|
||||
/** Whether of not the node is visible. Default is true */
|
||||
CCX_PROPERTY(bool, m_bIsVisible, IsVisible)
|
||||
/** Whether of not the node is visible. Default is true */
|
||||
CCX_PROPERTY(bool, m_bIsVisible, IsVisible)
|
||||
|
||||
/** anchorPoint is the point around which all transformations and positioning manipulations take place.
|
||||
It's like a pin in the node where it is "attached" to its parent.
|
||||
The anchorPoint is normalized, like a percentage. (0,0) means the bottom-left corner and (1,1) means the top-right corner.
|
||||
But you can use values higher than (1,1) and lower than (0,0) too.
|
||||
The default anchorPoint is (0.5,0.5), so it starts in the center of the node.
|
||||
@since v0.8
|
||||
*/
|
||||
CCX_PROPERTY(CGPoint, m_tAnchorPoint, AnchorPoint)
|
||||
/** anchorPoint is the point around which all transformations and positioning manipulations take place.
|
||||
It's like a pin in the node where it is "attached" to its parent.
|
||||
The anchorPoint is normalized, like a percentage. (0,0) means the bottom-left corner and (1,1) means the top-right corner.
|
||||
But you can use values higher than (1,1) and lower than (0,0) too.
|
||||
The default anchorPoint is (0.5,0.5), so it starts in the center of the node.
|
||||
@since v0.8
|
||||
*/
|
||||
CCX_PROPERTY(CGPoint, m_tAnchorPoint, AnchorPoint)
|
||||
|
||||
/** The anchorPoint in absolute pixels.
|
||||
Since v0.8 you can only read it. If you wish to modify it, use anchorPoint instead
|
||||
*/
|
||||
CCX_PROPERTY_READONLY(CGPoint, m_tAnchorPointInPixels, AnchorPointInPixels)
|
||||
|
||||
/** The untransformed size of the node.
|
||||
The contentSize remains the same no matter the node is scaled or rotated.
|
||||
All nodes has a size. Layer and Scene has the same size of the screen.
|
||||
@since v0.8
|
||||
*/
|
||||
CCX_PROPERTY(CGSize, m_tContentSize, ContentSize)
|
||||
/** The anchorPoint in absolute pixels.
|
||||
Since v0.8 you can only read it. If you wish to modify it, use anchorPoint instead
|
||||
*/
|
||||
CCX_PROPERTY_READONLY(CGPoint, m_tAnchorPointInPixels, AnchorPointInPixels)
|
||||
|
||||
/** whether or not the node is running */
|
||||
CCX_PROPERTY_READONLY(bool, m_bIsRunning, IsRunning)
|
||||
/** The untransformed size of the node.
|
||||
The contentSize remains the same no matter the node is scaled or rotated.
|
||||
All nodes has a size. Layer and Scene has the same size of the screen.
|
||||
@since v0.8
|
||||
*/
|
||||
CCX_PROPERTY(CGSize, m_tContentSize, ContentSize)
|
||||
|
||||
/** A weak reference to the parent */
|
||||
CCX_PROPERTY(CCNode *, m_pParent, Parent)
|
||||
/** The untransformed size of the node in Pixels
|
||||
The contentSize remains the same no matter the node is scaled or rotated.
|
||||
All nodes has a size. Layer and Scene has the same size of the screen.
|
||||
@since v0.8
|
||||
*/
|
||||
CCX_PROPERTY(CGSize, m_tContentSizeInPixels, ContentSizeInPixels)
|
||||
|
||||
/** 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.
|
||||
*/
|
||||
CCX_PROPERTY(bool, m_bIsRelativeAnchorPoint, IsRelativeAnchorPoint)
|
||||
/** whether or not the node is running */
|
||||
CCX_PROPERTY_READONLY(bool, m_bIsRunning, IsRunning)
|
||||
|
||||
/** A tag used to identify the node easily */
|
||||
CCX_PROPERTY(int, m_nTag, Tag)
|
||||
/** A weak reference to the parent */
|
||||
CCX_PROPERTY(CCNode *, m_pParent, Parent)
|
||||
|
||||
/** A custom user data pointer */
|
||||
CCX_PROPERTY(void *, m_pUserData, UserData)
|
||||
|
||||
protected:
|
||||
/** 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.
|
||||
*/
|
||||
CCX_PROPERTY(bool, m_bIsRelativeAnchorPoint, IsRelativeAnchorPoint)
|
||||
|
||||
// transform
|
||||
CGAffineTransform m_tTransform, m_tInverse;
|
||||
/** A tag used to identify the node easily */
|
||||
CCX_PROPERTY(int, m_nTag, Tag)
|
||||
|
||||
/** A custom user data pointer */
|
||||
CCX_PROPERTY(void *, m_pUserData, UserData)
|
||||
|
||||
protected:
|
||||
|
||||
// transform
|
||||
CGAffineTransform m_tTransform, m_tInverse;
|
||||
|
||||
#ifdef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
||||
GLfloat m_pTransformGL[16];
|
||||
GLfloat m_pTransformGL[16];
|
||||
#endif
|
||||
// To reduce memory, place bools that are not properties here:
|
||||
bool m_bIsTransformDirty;
|
||||
bool m_bIsInverseDirty;
|
||||
// To reduce memory, place bools that are not properties here:
|
||||
bool m_bIsTransformDirty;
|
||||
bool m_bIsInverseDirty;
|
||||
|
||||
#ifdef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
||||
bool m_bIsTransformGLDirty;
|
||||
bool m_bIsTransformGLDirty;
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
//! lazy allocs
|
||||
void childrenAlloc(void);
|
||||
private:
|
||||
|
||||
//! helper that reorder a child
|
||||
void insertChild(CCNode* child, int z);
|
||||
//! lazy allocs
|
||||
void childrenAlloc(void);
|
||||
|
||||
//! used internally to alter the zOrder variable. DON'T call this method manually
|
||||
void setZOrder(int z);
|
||||
//! helper that reorder a child
|
||||
void insertChild(CCNode* child, int z);
|
||||
|
||||
void detachChild(CCNode *child, bool doCleanup);
|
||||
//! used internally to alter the zOrder variable. DON'T call this method manually
|
||||
void setZOrder(int z);
|
||||
|
||||
typedef void (CCNode::*callbackFunc)(void);
|
||||
void detachChild(CCNode *child, bool doCleanup);
|
||||
|
||||
void arrayMakeObjectsPerformSelector(NSMutableArray<CCNode*> * pArray, callbackFunc func);
|
||||
typedef void (CCNode::*callbackFunc)(void);
|
||||
|
||||
CGPoint convertToWindowSpace(CGPoint nodePoint);
|
||||
void arrayMakeObjectsPerformSelector(NSMutableArray<CCNode*> * pArray, callbackFunc func);
|
||||
|
||||
public:
|
||||
CGPoint convertToWindowSpace(CGPoint nodePoint);
|
||||
|
||||
CCNode();
|
||||
public:
|
||||
|
||||
virtual ~CCNode();
|
||||
CCNode();
|
||||
|
||||
char * description(void);
|
||||
virtual ~CCNode();
|
||||
|
||||
/** allocates and initializes a node.
|
||||
The node will be created as "autorelease".
|
||||
*/
|
||||
static CCNode * node(void);
|
||||
char * description(void);
|
||||
|
||||
//scene managment
|
||||
/** allocates and initializes a node.
|
||||
The node will be created as "autorelease".
|
||||
*/
|
||||
static CCNode * node(void);
|
||||
|
||||
/** callback that is called every time the CCNode enters the 'stage'.
|
||||
If the CCNode enters the 'stage' with a transition, this callback is called when the transition starts.
|
||||
During onEnter you can't a "sister/brother" node.
|
||||
*/
|
||||
virtual void onEnter();
|
||||
//scene managment
|
||||
|
||||
/** callback that is called when the CCNode enters in the 'stage'.
|
||||
If the CCNode enters the 'stage' with a transition, this callback is called when the transition finishes.
|
||||
@since v0.8
|
||||
*/
|
||||
virtual void onEnterTransitionDidFinish();
|
||||
/** callback that is called every time the CCNode enters the 'stage'.
|
||||
If the CCNode enters the 'stage' with a transition, this callback is called when the transition starts.
|
||||
During onEnter you can't a "sister/brother" node.
|
||||
*/
|
||||
virtual void onEnter();
|
||||
|
||||
/** callback that is called every time the CCNode leaves the 'stage'.
|
||||
If the CCNode leaves the 'stage' with a transition, this callback is called when the transition finishes.
|
||||
During onExit you can't a "sister/brother" node.
|
||||
*/
|
||||
virtual void onExit();
|
||||
/** callback that is called when the CCNode enters in the 'stage'.
|
||||
If the CCNode enters the 'stage' with a transition, this callback is called when the transition finishes.
|
||||
@since v0.8
|
||||
*/
|
||||
virtual void onEnterTransitionDidFinish();
|
||||
|
||||
// composition: ADD
|
||||
/** callback that is called every time the CCNode leaves the 'stage'.
|
||||
If the CCNode leaves the 'stage' with a transition, this callback is called when the transition finishes.
|
||||
During onExit you can't a "sister/brother" node.
|
||||
*/
|
||||
virtual void onExit();
|
||||
|
||||
/** Adds a child to the container with z-order as 0.
|
||||
It returns self, so you can chain several addChilds.
|
||||
@since v0.7.1
|
||||
*/
|
||||
virtual CCNode * addChild(CCNode * child);
|
||||
// composition: ADD
|
||||
|
||||
/** Adds a child to the container with a z-order
|
||||
It returns self, so you can chain several addChilds.
|
||||
@since v0.7.1
|
||||
*/
|
||||
virtual CCNode * addChild(CCNode * child, int zOrder);
|
||||
/** Adds a child to the container with z-order as 0.
|
||||
If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately.
|
||||
@since v0.7.1
|
||||
*/
|
||||
virtual void addChild(CCNode * child);
|
||||
|
||||
/** Adds a child to the container with z order and tag
|
||||
It returns self, so you can chain several addChilds.
|
||||
@since v0.7.1
|
||||
*/
|
||||
virtual CCNode * addChild(CCNode * child, int zOrder, int tag);
|
||||
/** Adds a child to the container with a z-order
|
||||
If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately.
|
||||
@since v0.7.1
|
||||
*/
|
||||
virtual void addChild(CCNode * child, int zOrder);
|
||||
|
||||
// composition: REMOVE
|
||||
/** Adds a child to the container with z order and tag
|
||||
If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately.
|
||||
@since v0.7.1
|
||||
*/
|
||||
virtual void addChild(CCNode * child, int zOrder, int tag);
|
||||
|
||||
/** Remove itself from its parent node. If cleanup is true, then also remove all actions and callbacks.
|
||||
If the node orphan, then nothing happens.
|
||||
@since v0.99.3
|
||||
*/
|
||||
void removeFromParentAndCleanup(bool cleanup);
|
||||
// composition: REMOVE
|
||||
|
||||
/** Removes a child from the container. It will also cleanup all running actions depending on the cleanup parameter.
|
||||
@since v0.7.1
|
||||
*/
|
||||
virtual void removeChild(CCNode* child, bool cleanup);
|
||||
/** Remove itself from its parent node. If cleanup is true, then also remove all actions and callbacks.
|
||||
If the node orphan, then nothing happens.
|
||||
@since v0.99.3
|
||||
*/
|
||||
void removeFromParentAndCleanup(bool cleanup);
|
||||
|
||||
/** Removes a child from the container by tag value. It will also cleanup all running actions depending on the cleanup parameter
|
||||
@since v0.7.1
|
||||
*/
|
||||
void removeChildByTag(int tag, bool cleanup);
|
||||
/** Removes a child from the container. It will also cleanup all running actions depending on the cleanup parameter.
|
||||
@since v0.7.1
|
||||
*/
|
||||
virtual void removeChild(CCNode* child, bool cleanup);
|
||||
|
||||
/** Removes all children from the container and do a cleanup all running actions depending on the cleanup parameter.
|
||||
@since v0.7.1
|
||||
*/
|
||||
virtual void removeAllChildrenWithCleanup(bool cleanup);
|
||||
/** Removes a child from the container by tag value. It will also cleanup all running actions depending on the cleanup parameter
|
||||
@since v0.7.1
|
||||
*/
|
||||
void removeChildByTag(int tag, bool cleanup);
|
||||
|
||||
// composition: GET
|
||||
/** Gets a child from the container given its tag
|
||||
@return returns a CCNode object
|
||||
@since v0.7.1
|
||||
*/
|
||||
CCNode * getChildByTag(int tag);
|
||||
/** Removes all children from the container and do a cleanup all running actions depending on the cleanup parameter.
|
||||
@since v0.7.1
|
||||
*/
|
||||
virtual void removeAllChildrenWithCleanup(bool cleanup);
|
||||
|
||||
/** Reorders a child according to a new z value.
|
||||
* The child MUST be already added.
|
||||
*/
|
||||
virtual void reorderChild(CCNode * child, int zOrder);
|
||||
// composition: GET
|
||||
/** Gets a child from the container given its tag
|
||||
@return returns a CCNode object
|
||||
@since v0.7.1
|
||||
*/
|
||||
CCNode * getChildByTag(int tag);
|
||||
|
||||
/** Stops all running actions and schedulers
|
||||
@since v0.8
|
||||
*/
|
||||
virtual void cleanup(void);
|
||||
/** Reorders a child according to a new z value.
|
||||
* The child MUST be already added.
|
||||
*/
|
||||
virtual void reorderChild(CCNode * child, int zOrder);
|
||||
|
||||
// draw
|
||||
/** Stops all running actions and schedulers
|
||||
@since v0.8
|
||||
*/
|
||||
virtual void cleanup(void);
|
||||
|
||||
/** Override this method to draw your own node.
|
||||
The following GL states will be enabled by default:
|
||||
- glEnableClientState(GL_VERTEX_ARRAY);
|
||||
- glEnableClientState(GL_COLOR_ARRAY);
|
||||
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
- glEnable(GL_TEXTURE_2D);
|
||||
|
||||
AND YOU SHOULD NOT DISABLE THEM AFTER DRAWING YOUR NODE
|
||||
|
||||
But if you enable any other GL state, you should disable it after drawing your node.
|
||||
*/
|
||||
virtual void draw(void);
|
||||
|
||||
/** recursive method that visit its children and draw them */
|
||||
virtual void visit(void);
|
||||
|
||||
// transformations
|
||||
|
||||
/** performs OpenGL view-matrix transformation based on position, scale, rotation and other attributes. */
|
||||
void transform(void);
|
||||
|
||||
/** performs OpenGL view-matrix transformation of it's ancestors.
|
||||
Generally the ancestors are already transformed, but in certain cases (eg: attaching a FBO)
|
||||
it's necessary to transform the ancestors again.
|
||||
@since v0.7.2
|
||||
*/
|
||||
void transformAncestors(void);
|
||||
|
||||
/** returns a "local" axis aligned bounding box of the node.
|
||||
The returned box is relative only to its parent.
|
||||
|
||||
@since v0.8.2
|
||||
*/
|
||||
CGRect boundingBox(void);
|
||||
|
||||
// actions
|
||||
|
||||
/** Executes an action, and returns the action that is executed.
|
||||
The node becomes the action's target.
|
||||
@warning Starting from v0.8 actions don't retain their target anymore.
|
||||
@since v0.7.1
|
||||
@return An Action pointer
|
||||
*/
|
||||
|
||||
CCAction* runAction(CCAction* action);
|
||||
|
||||
/** Removes all actions from the running action list */
|
||||
void stopAllActions(void);
|
||||
|
||||
/** Removes an action from the running action list */
|
||||
void stopAction(CCAction* action);
|
||||
|
||||
/** Removes an action from the running action list given its tag
|
||||
@since v0.7.1
|
||||
*/
|
||||
void stopActionByTag(int tag);
|
||||
|
||||
/** Gets an action from the running action list given its tag
|
||||
@since v0.7.1
|
||||
@return the Action the with the given tag
|
||||
*/
|
||||
CCAction* getActionByTag(int tag);
|
||||
|
||||
/** Returns the numbers of actions that are running plus the ones that are schedule to run (actions in actionsToAdd and actions arrays).
|
||||
* Composable actions are counted as 1 action. Example:
|
||||
* If you are running 1 Sequence of 7 actions, it will return 1.
|
||||
* If you are running 7 Sequences of 2 actions, it will return 7.
|
||||
*/
|
||||
int numberOfRunningActions(void);
|
||||
|
||||
|
||||
// timers
|
||||
|
||||
/** check whether a selector is scheduled. */
|
||||
bool isScheduled(SEL_SCHEDULE selector);
|
||||
|
||||
/** schedules the "update" method. It will use the order number 0. This method will be called every frame.
|
||||
Scheduled methods with a lower order value will be called before the ones that have a higher order value.
|
||||
Only one "update" method could be scheduled per node.
|
||||
|
||||
@since v0.99.3
|
||||
*/
|
||||
void scheduleUpdate(void);
|
||||
|
||||
/** schedules the "update" selector with a custom priority. This selector will be called every frame.
|
||||
Scheduled selectors with a lower priority will be called before the ones that have a higher value.
|
||||
Only one "update" selector could be scheduled per node (You can't have 2 'update' selectors).
|
||||
|
||||
@since v0.99.3
|
||||
*/
|
||||
void scheduleUpdateWithPriority(int priority);
|
||||
|
||||
/* unschedules the "update" method.
|
||||
|
||||
@since v0.99.3
|
||||
*/
|
||||
void unscheduleUpdate(void);
|
||||
|
||||
/** schedules a selector.
|
||||
The scheduled selector will be ticked every frame
|
||||
*/
|
||||
void schedule(SEL_SCHEDULE selector);
|
||||
|
||||
/** schedules a custom selector with an interval time in seconds.
|
||||
If time is 0 it will be ticked every frame.
|
||||
If time is 0, it is recommended to use 'scheduleUpdate' instead.
|
||||
If the selector is already scheduled, then the interval parameter
|
||||
will be updated without scheduling it again.
|
||||
*/
|
||||
void schedule(SEL_SCHEDULE selector, ccTime interval);
|
||||
|
||||
/** unschedules a custom selector.*/
|
||||
void unschedule(SEL_SCHEDULE selector);
|
||||
|
||||
/** unschedule all scheduled selectors: custom selectors, and the 'update' selector.
|
||||
Actions are not affected by this method.
|
||||
@since v0.99.3
|
||||
*/
|
||||
void unscheduleAllSelectors(void);
|
||||
|
||||
/** resumes all scheduled selectors and actions.
|
||||
Called internally by onEnter
|
||||
*/
|
||||
void resumeSchedulerAndActions(void);
|
||||
/** pauses all scheduled selectors and actions.
|
||||
Called internally by onExit
|
||||
*/
|
||||
void pauseSchedulerAndActions(void);
|
||||
|
||||
// SelecterProtocol methods
|
||||
|
||||
virtual void selectorProtocolRetain(void);
|
||||
virtual void selectorProtocolRelease(void);
|
||||
|
||||
virtual CCRGBAProtocol* convertToRGBAProtocol(void) { return NULL; }
|
||||
virtual CCLabelProtocol* convertToLabelProtocol(void) { return NULL; }
|
||||
|
||||
// transformation methods
|
||||
|
||||
/** Returns the local affine transform matrix
|
||||
@since v0.7.1
|
||||
*/
|
||||
CGAffineTransform nodeToParentTransform(void);
|
||||
|
||||
/** Returns the inverse local affine transform matrix
|
||||
@since v0.7.1
|
||||
*/
|
||||
CGAffineTransform parentToNodeTransform(void);
|
||||
|
||||
/** Retrusn the world affine transform matrix
|
||||
@since v0.7.1
|
||||
*/
|
||||
CGAffineTransform nodeToWorldTransform(void);
|
||||
|
||||
/** Returns the inverse world affine transform matrix
|
||||
@since v0.7.1
|
||||
*/
|
||||
CGAffineTransform worldToNodeTransform(void);
|
||||
|
||||
/** converts a world coordinate to local coordinate
|
||||
@since v0.7.1
|
||||
*/
|
||||
CGPoint convertToNodeSpace(CGPoint worldPoint);
|
||||
/** converts local coordinate to world space
|
||||
@since v0.7.1
|
||||
*/
|
||||
CGPoint convertToWorldSpace(CGPoint nodePoint);
|
||||
/** converts a world coordinate to local coordinate
|
||||
treating the returned/received node point as anchor relative
|
||||
@since v0.7.1
|
||||
*/
|
||||
CGPoint convertToNodeSpaceAR(CGPoint worldPoint);
|
||||
/** converts local coordinate to world space
|
||||
treating the returned/received node point as anchor relative
|
||||
@since v0.7.1
|
||||
*/
|
||||
CGPoint convertToWorldSpaceAR(CGPoint nodePoint);
|
||||
/** convenience methods which take a CCTouch instead of CGPoint
|
||||
@since v0.7.1
|
||||
*/
|
||||
CGPoint convertTouchToNodeSpace(CCTouch * touch);
|
||||
|
||||
/** converts a CCTouch (world coordinates) into a local coordiante. This method is AR (Anchor Relative).
|
||||
@since v0.7.1
|
||||
*/
|
||||
CGPoint convertTouchToNodeSpaceAR(CCTouch * touch);
|
||||
|
||||
};
|
||||
// draw
|
||||
|
||||
/** Override this method to draw your own node.
|
||||
The following GL states will be enabled by default:
|
||||
- glEnableClientState(GL_VERTEX_ARRAY);
|
||||
- glEnableClientState(GL_COLOR_ARRAY);
|
||||
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
- glEnable(GL_TEXTURE_2D);
|
||||
|
||||
AND YOU SHOULD NOT DISABLE THEM AFTER DRAWING YOUR NODE
|
||||
|
||||
But if you enable any other GL state, you should disable it after drawing your node.
|
||||
*/
|
||||
virtual void draw(void);
|
||||
|
||||
/** recursive method that visit its children and draw them */
|
||||
virtual void visit(void);
|
||||
|
||||
// transformations
|
||||
|
||||
/** performs OpenGL view-matrix transformation based on position, scale, rotation and other attributes. */
|
||||
void transform(void);
|
||||
|
||||
/** performs OpenGL view-matrix transformation of it's ancestors.
|
||||
Generally the ancestors are already transformed, but in certain cases (eg: attaching a FBO)
|
||||
it's necessary to transform the ancestors again.
|
||||
@since v0.7.2
|
||||
*/
|
||||
void transformAncestors(void);
|
||||
|
||||
/** returns a "local" axis aligned bounding box of the node.
|
||||
The returned box is relative only to its parent.
|
||||
|
||||
@since v0.8.2
|
||||
*/
|
||||
CGRect boundingBox(void);
|
||||
|
||||
/** returns a "local" axis aligned bounding box of the node in pixels.
|
||||
The returned box is relative only to its parent.
|
||||
The returned box is in Points.
|
||||
|
||||
@since v0.99.5
|
||||
*/
|
||||
CGRect boundingBoxInPixels(void);
|
||||
|
||||
// actions
|
||||
|
||||
/** Executes an action, and returns the action that is executed.
|
||||
The node becomes the action's target.
|
||||
@warning Starting from v0.8 actions don't retain their target anymore.
|
||||
@since v0.7.1
|
||||
@return An Action pointer
|
||||
*/
|
||||
|
||||
CCAction* runAction(CCAction* action);
|
||||
|
||||
/** Removes all actions from the running action list */
|
||||
void stopAllActions(void);
|
||||
|
||||
/** Removes an action from the running action list */
|
||||
void stopAction(CCAction* action);
|
||||
|
||||
/** Removes an action from the running action list given its tag
|
||||
@since v0.7.1
|
||||
*/
|
||||
void stopActionByTag(int tag);
|
||||
|
||||
/** Gets an action from the running action list given its tag
|
||||
@since v0.7.1
|
||||
@return the Action the with the given tag
|
||||
*/
|
||||
CCAction* getActionByTag(int tag);
|
||||
|
||||
/** Returns the numbers of actions that are running plus the ones that are schedule to run (actions in actionsToAdd and actions arrays).
|
||||
* Composable actions are counted as 1 action. Example:
|
||||
* If you are running 1 Sequence of 7 actions, it will return 1.
|
||||
* If you are running 7 Sequences of 2 actions, it will return 7.
|
||||
*/
|
||||
int numberOfRunningActions(void);
|
||||
|
||||
|
||||
// timers
|
||||
|
||||
/** check whether a selector is scheduled. */
|
||||
bool isScheduled(SEL_SCHEDULE selector);
|
||||
|
||||
/** schedules the "update" method. It will use the order number 0. This method will be called every frame.
|
||||
Scheduled methods with a lower order value will be called before the ones that have a higher order value.
|
||||
Only one "update" method could be scheduled per node.
|
||||
|
||||
@since v0.99.3
|
||||
*/
|
||||
void scheduleUpdate(void);
|
||||
|
||||
/** schedules the "update" selector with a custom priority. This selector will be called every frame.
|
||||
Scheduled selectors with a lower priority will be called before the ones that have a higher value.
|
||||
Only one "update" selector could be scheduled per node (You can't have 2 'update' selectors).
|
||||
|
||||
@since v0.99.3
|
||||
*/
|
||||
void scheduleUpdateWithPriority(int priority);
|
||||
|
||||
/* unschedules the "update" method.
|
||||
|
||||
@since v0.99.3
|
||||
*/
|
||||
void unscheduleUpdate(void);
|
||||
|
||||
/** schedules a selector.
|
||||
The scheduled selector will be ticked every frame
|
||||
*/
|
||||
void schedule(SEL_SCHEDULE selector);
|
||||
|
||||
/** schedules a custom selector with an interval time in seconds.
|
||||
If time is 0 it will be ticked every frame.
|
||||
If time is 0, it is recommended to use 'scheduleUpdate' instead.
|
||||
If the selector is already scheduled, then the interval parameter
|
||||
will be updated without scheduling it again.
|
||||
*/
|
||||
void schedule(SEL_SCHEDULE selector, ccTime interval);
|
||||
|
||||
/** unschedules a custom selector.*/
|
||||
void unschedule(SEL_SCHEDULE selector);
|
||||
|
||||
/** unschedule all scheduled selectors: custom selectors, and the 'update' selector.
|
||||
Actions are not affected by this method.
|
||||
@since v0.99.3
|
||||
*/
|
||||
void unscheduleAllSelectors(void);
|
||||
|
||||
/** resumes all scheduled selectors and actions.
|
||||
Called internally by onEnter
|
||||
*/
|
||||
void resumeSchedulerAndActions(void);
|
||||
/** pauses all scheduled selectors and actions.
|
||||
Called internally by onExit
|
||||
*/
|
||||
void pauseSchedulerAndActions(void);
|
||||
|
||||
// SelecterProtocol methods
|
||||
|
||||
virtual void selectorProtocolRetain(void);
|
||||
virtual void selectorProtocolRelease(void);
|
||||
|
||||
virtual CCRGBAProtocol* convertToRGBAProtocol(void) { return NULL; }
|
||||
virtual CCLabelProtocol* convertToLabelProtocol(void) { return NULL; }
|
||||
|
||||
// transformation methods
|
||||
|
||||
/** Returns the matrix that transform the node's (local) space coordinates into the parent's space coordinates.
|
||||
The matrix is in Pixels.
|
||||
@since v0.7.1
|
||||
*/
|
||||
CGAffineTransform nodeToParentTransform(void);
|
||||
|
||||
/** Returns the matrix that transform parent's space coordinates to the node's (local) space coordinates.
|
||||
The matrix is in Pixels.
|
||||
@since v0.7.1
|
||||
*/
|
||||
CGAffineTransform parentToNodeTransform(void);
|
||||
|
||||
/** Retrusn the world affine transform matrix. The matrix is in Pixels.
|
||||
@since v0.7.1
|
||||
*/
|
||||
CGAffineTransform nodeToWorldTransform(void);
|
||||
|
||||
/** Returns the inverse world affine transform matrix. The matrix is in Pixels.
|
||||
@since v0.7.1
|
||||
*/
|
||||
CGAffineTransform worldToNodeTransform(void);
|
||||
|
||||
/** Converts a Point to node (local) space coordinates. The result is in Points.
|
||||
@since v0.7.1
|
||||
*/
|
||||
CGPoint convertToNodeSpace(CGPoint worldPoint);
|
||||
/** Converts a Point to world space coordinates. The result is in Points.
|
||||
@since v0.7.1
|
||||
*/
|
||||
CGPoint convertToWorldSpace(CGPoint nodePoint);
|
||||
/** Converts a Point to node (local) space coordinates. The result is in Points.
|
||||
treating the returned/received node point as anchor relative.
|
||||
@since v0.7.1
|
||||
*/
|
||||
CGPoint convertToNodeSpaceAR(CGPoint worldPoint);
|
||||
/** Converts a local Point to world space coordinates.The result is in Points.
|
||||
treating the returned/received node point as anchor relative.
|
||||
@since v0.7.1
|
||||
*/
|
||||
CGPoint convertToWorldSpaceAR(CGPoint nodePoint);
|
||||
|
||||
/** convenience methods which take a CCTouch instead of CGPoint
|
||||
@since v0.7.1
|
||||
*/
|
||||
CGPoint convertTouchToNodeSpace(CCTouch * touch);
|
||||
|
||||
/** converts a CCTouch (world coordinates) into a local coordiante. This method is AR (Anchor Relative).
|
||||
@since v0.7.1
|
||||
*/
|
||||
CGPoint convertTouchToNodeSpaceAR(CCTouch * touch);
|
||||
|
||||
};
|
||||
}//namespace cocos2d
|
||||
|
||||
#endif // __CCNODE_H__
|
||||
#endif // __PLATFOMR_CCNODE_H__
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -101,7 +101,13 @@ simple macro that swaps 2 variables
|
|||
/** @def CC_BLEND_SRC
|
||||
default gl blend src function. Compatible with premultiplied alpha images.
|
||||
*/
|
||||
#define CC_BLEND_SRC GL_ONE
|
||||
#if CC_OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA
|
||||
#define CC_BLEND_SRC GL_ONE
|
||||
#define CC_BLEND_DST GL_ONE_MINUS_SRC_ALPHA
|
||||
#else
|
||||
#define CC_BLEND_SRC GL_SRC_ALPHA
|
||||
#define CC_BLEND_DST GL_ONE_MINUS_SRC_ALPHA
|
||||
#endif // ! CC_OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA
|
||||
|
||||
/** @def CC_BLEND_DST
|
||||
default gl blend dst function. Compatible with premultiplied alpha images.
|
||||
|
@ -156,24 +162,29 @@ default gl blend src function. Compatible with premultiplied alpha images.
|
|||
|
||||
//---- todo: replace with uphone window
|
||||
|
||||
|
||||
// #define CC_DIRECTOR_INIT() \
|
||||
// do { \
|
||||
// window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; \
|
||||
// if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] ) \
|
||||
// [CCDirector setDirectorType:kCCDirectorTypeNSTimer]; \
|
||||
// CCDirector *__director = [CCDirector sharedDirector]; \
|
||||
// [__director setDeviceOrientation:kCCDeviceOrientationPortrait]; \
|
||||
// [__director setDisplayFPS:NO]; \
|
||||
// [__director setAnimationInterval:1.0/60]; \
|
||||
// EAGLView *__glView = [EAGLView viewWithFrame:[window bounds] \
|
||||
// pixelFormat:kEAGLColorFormatRGB565 \
|
||||
// depthFormat:0 GL_DEPTH_COMPONENT24_OES \
|
||||
// preserveBackbuffer:NO]; \
|
||||
// [__director setOpenGLView:__glView]; \
|
||||
// [window addSubview:__glView]; \
|
||||
// [window makeKeyAndVisible]; \
|
||||
// } while(0)
|
||||
/*
|
||||
#define CC_DIRECTOR_INIT() \
|
||||
do { \
|
||||
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; \
|
||||
if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] ) \
|
||||
[CCDirector setDirectorType:kCCDirectorTypeNSTimer]; \
|
||||
CCDirector *__director = [CCDirector sharedDirector]; \
|
||||
[__director setDeviceOrientation:kCCDeviceOrientationPortrait]; \
|
||||
[__director setDisplayFPS:NO]; \
|
||||
[__director setAnimationInterval:1.0/60]; \
|
||||
EAGLView *__glView = [EAGLView viewWithFrame:[window bounds] \
|
||||
pixelFormat:kEAGLColorFormatRGB565 \
|
||||
depthFormat:0 \
|
||||
preserveBackbuffer:NO \
|
||||
sharegroup:nil \
|
||||
multiSampling:NO \
|
||||
numberOfSamples:0 \
|
||||
]; \
|
||||
[__director setOpenGLView:__glView]; \
|
||||
[window addSubview:__glView]; \
|
||||
[window makeKeyAndVisible]; \
|
||||
} while(0)
|
||||
*/
|
||||
|
||||
|
||||
/** @def CC_DIRECTOR_END
|
||||
|
@ -189,11 +200,50 @@ default gl blend src function. Compatible with premultiplied alpha images.
|
|||
// #define CC_DIRECTOR_END() \
|
||||
// do { \
|
||||
// CCDirector *__director = [CCDirector sharedDirector]; \
|
||||
// EAGLView *__view = [__director openGLView]; \
|
||||
// CC_GLVIEW *__view = [__director openGLView]; \
|
||||
// [__view removeFromSuperview]; \
|
||||
// [__director end]; \
|
||||
// } while(0)
|
||||
|
||||
#if CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||
|
||||
/****************************/
|
||||
/** RETINA DISPLAY ENABLED **/
|
||||
/****************************/
|
||||
|
||||
/** @def CC_CONTENT_SCALE_FACTOR
|
||||
On Mac it returns 1;
|
||||
On iPhone it returns 2 if RetinaDisplay is On. Otherwise it returns 1
|
||||
*/
|
||||
#import "Platforms/iOS/CCDirectorIOS.h"
|
||||
#define CC_CONTENT_SCALE_FACTOR() __ccContentScaleFactor
|
||||
|
||||
|
||||
/** @def CC_RECT_PIXELS_TO_POINTS
|
||||
Converts a rect in pixels to points
|
||||
*/
|
||||
#define CC_RECT_PIXELS_TO_POINTS(__pixels__) \
|
||||
CGRectMake( (__pixels__).origin.x / CC_CONTENT_SCALE_FACTOR(), (__pixels__).origin.y / CC_CONTENT_SCALE_FACTOR(), \
|
||||
(__pixels__).size.width / CC_CONTENT_SCALE_FACTOR(), (__pixels__).size.height / CC_CONTENT_SCALE_FACTOR() )
|
||||
|
||||
/** @def CC_RECT_POINTS_TO_PIXELS
|
||||
Converts a rect in points to pixels
|
||||
*/
|
||||
#define CC_RECT_POINTS_TO_PIXELS(__points__) \
|
||||
CGRectMake( (__points__).origin.x * CC_CONTENT_SCALE_FACTOR(), (__points__).origin.y * CC_CONTENT_SCALE_FACTOR(), \
|
||||
(__points__).size.width * CC_CONTENT_SCALE_FACTOR(), (__points__).size.height * CC_CONTENT_SCALE_FACTOR() )
|
||||
|
||||
#else // retina disabled
|
||||
|
||||
/*****************************/
|
||||
/** RETINA DISPLAY DISABLED **/
|
||||
/*****************************/
|
||||
|
||||
#define CC_CONTENT_SCALE_FACTOR() 1
|
||||
#define CC_RECT_PIXELS_TO_POINTS(__pixels__) __pixels__
|
||||
#define CC_RECT_POINTS_TO_PIXELS(__points__) __points__
|
||||
|
||||
#endif // CC_IS_RETINA_DISPLAY_SUPPORTED
|
||||
|
||||
#ifndef FLT_EPSILON
|
||||
#define FLT_EPSILON 1.192092896e-07F
|
||||
|
|
|
@ -46,9 +46,11 @@ CCNode::CCNode(void)
|
|||
,m_fScaleX(1.0f)
|
||||
,m_fScaleY(1.0f)
|
||||
,m_tPosition(CGPointZero)
|
||||
,m_tPositionInPixels(CGPointZero)
|
||||
,m_tAnchorPointInPixels(CGPointZero)
|
||||
,m_tAnchorPoint(CGPointZero)
|
||||
,m_tContentSize(CGSizeZero)
|
||||
,m_tContentSizeInPixels(CGSizeZero)
|
||||
// "whole screen" objects. like Scenes and Layers, should set isRelativeAnchorPoint to false
|
||||
,m_bIsRelativeAnchorPoint(true)
|
||||
,m_bIsTransformDirty(true)
|
||||
|
@ -139,7 +141,7 @@ float CCNode::getVertexZ()
|
|||
/// vertexZ setter
|
||||
void CCNode::setVertexZ(float var)
|
||||
{
|
||||
m_fVertexZ = var;
|
||||
m_fVertexZ = var * CC_CONTENT_SCALE_FACTOR();
|
||||
}
|
||||
|
||||
|
||||
|
@ -219,12 +221,41 @@ CGPoint CCNode::getPosition()
|
|||
void CCNode::setPosition(CGPoint newPosition)
|
||||
{
|
||||
m_tPosition = newPosition;
|
||||
if (CC_CONTENT_SCALE_FACTOR() == 1)
|
||||
{
|
||||
m_tAnchorPointInPixels = m_tPosition;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_tAnchorPointInPixels = ccpMult(newPosition, CC_CONTENT_SCALE_FACTOR());
|
||||
}
|
||||
|
||||
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
||||
#ifdef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
||||
m_bIsTransformGLDirty = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
void CCNode::setPositionInPixels(CGPoint newPosition)
|
||||
{
|
||||
m_tAnchorPointInPixels = newPosition;
|
||||
|
||||
if ( CC_CONTENT_SCALE_FACTOR() == 1)
|
||||
{
|
||||
m_tPosition = m_tAnchorPointInPixels;
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
/// children getter
|
||||
NSMutableArray<CCNode*> * CCNode::getChildren()
|
||||
{
|
||||
|
@ -282,7 +313,7 @@ void CCNode::setAnchorPoint(CGPoint point)
|
|||
if( ! CGPoint::CGPointEqualToPoint(point, m_tAnchorPoint) )
|
||||
{
|
||||
m_tAnchorPoint = point;
|
||||
this->m_tAnchorPointInPixels = ccp( m_tContentSize.width * m_tAnchorPoint.x, m_tContentSize.height * m_tAnchorPoint.y );
|
||||
m_tAnchorPointInPixels = ccp( m_tContentSizeInPixels.width * m_tAnchorPoint.x, m_tContentSizeInPixels.height * m_tAnchorPoint.y );
|
||||
m_bIsTransformDirty = m_bIsInverseDirty = true;
|
||||
#ifdef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
|
||||
m_bIsTransformGLDirty = true;
|
||||
|
@ -315,6 +346,30 @@ void CCNode::setContentSize(CGSize size)
|
|||
}
|
||||
}
|
||||
|
||||
void CCNode::setContentSizeInPixels(CGSize size)
|
||||
{
|
||||
if (! CGSize::CGSizeEqualToSize(size, m_tContentSizeInPixels))
|
||||
{
|
||||
m_tContentSizeInPixels = size;
|
||||
|
||||
if (CC_CONTENT_SCALE_FACTOR() == 1)
|
||||
{
|
||||
m_tContentSize = m_tContentSizeInPixels;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_tContentSize = CGSizeMake(size.width / CC_CONTENT_SCALE_FACTOR(), size.height / CC_CONTENT_SCALE_FACTOR());
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// isRunning getter
|
||||
bool CCNode::getIsRunning()
|
||||
|
@ -376,7 +431,13 @@ void CCNode::setUserData(void *var)
|
|||
|
||||
CGRect CCNode::boundingBox()
|
||||
{
|
||||
CGRect rect = CGRectMake(0, 0, m_tContentSize.width, m_tContentSize.height);
|
||||
CGRect ret = boundingBoxInPixels();
|
||||
return CC_RECT_PIXELS_TO_POINTS(ret);
|
||||
}
|
||||
|
||||
CGRect CCNode::boundingBoxInPixels()
|
||||
{
|
||||
CGRect rect = CGRectMake(0, 0, m_tContentSizeInPixels.width, m_tContentSizeInPixels.height);
|
||||
return CGRectApplyAffineTransform(rect, nodeToParentTransform());
|
||||
}
|
||||
|
||||
|
@ -435,7 +496,7 @@ CCNode* CCNode::getChildByTag(int aTag)
|
|||
* If a class want's to extend the 'addChild' behaviour it only needs
|
||||
* to override this method
|
||||
*/
|
||||
CCNode * CCNode::addChild(CCNode *child, int zOrder, int tag)
|
||||
void CCNode::addChild(CCNode *child, int zOrder, int tag)
|
||||
{
|
||||
NSAssert( child != NULL, "Argument must be non-nil");
|
||||
NSAssert( child->m_pParent == NULL, "child already added. It can't be added again");
|
||||
|
@ -454,20 +515,20 @@ CCNode * CCNode::addChild(CCNode *child, int zOrder, int tag)
|
|||
if( m_bIsRunning )
|
||||
{
|
||||
child->onEnter();
|
||||
child->onEnterTransitionDidFinish();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
CCNode * CCNode::addChild(CCNode *child, int zOrder)
|
||||
void CCNode::addChild(CCNode *child, int zOrder)
|
||||
{
|
||||
NSAssert( child != NULL, "Argument must be non-nil");
|
||||
return this->addChild(child, zOrder, child->m_nTag);
|
||||
this->addChild(child, zOrder, child->m_nTag);
|
||||
}
|
||||
|
||||
CCNode * CCNode::addChild(CCNode *child)
|
||||
void CCNode::addChild(CCNode *child)
|
||||
{
|
||||
NSAssert( child != NULL, "Argument must be non-nil");
|
||||
return this->addChild(child, child->m_nZOrder, child->m_nTag);
|
||||
this->addChild(child, child->m_nZOrder, child->m_nTag);
|
||||
}
|
||||
|
||||
void CCNode::removeFromParentAndCleanup(bool cleanup)
|
||||
|
@ -570,30 +631,32 @@ void CCNode::detachChild(CCNode *child, bool doCleanup)
|
|||
// helper used by reorderChild & add
|
||||
void CCNode::insertChild(CCNode* child, int z)
|
||||
{
|
||||
int index=0;
|
||||
bool added = false;
|
||||
unsigned int index=0;
|
||||
|
||||
if(m_pChildren && m_pChildren->count() > 0)
|
||||
{
|
||||
CCNode* pNode;
|
||||
NSMutableArray<CCNode*>::NSMutableArrayIterator it;
|
||||
for( it = m_pChildren->begin(); it != m_pChildren->end(); it++)
|
||||
CCNode* pNode = m_pChildren->getLastObject();
|
||||
|
||||
// // quick comparison to improve performance
|
||||
if (! pNode || pNode->getZOrder() <= z)
|
||||
{
|
||||
pNode = (*it);
|
||||
|
||||
if ( pNode && pNode->m_nZOrder > z )
|
||||
{
|
||||
added = true;
|
||||
m_pChildren->insertObjectAtIndex(child, index);
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
m_pChildren->addObject(child);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NSMutableArray<CCNode*>::NSMutableArrayIterator it;
|
||||
for( it = m_pChildren->begin(); it != m_pChildren->end(); it++)
|
||||
{
|
||||
pNode = (*it);
|
||||
|
||||
if( ! added )
|
||||
{
|
||||
m_pChildren->addObject(child);
|
||||
if ( pNode && pNode->m_nZOrder > z )
|
||||
{
|
||||
m_pChildren->insertObjectAtIndex(child, index);
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
child->setZOrder(z);
|
||||
|
@ -714,14 +777,14 @@ void CCNode::transform()
|
|||
|
||||
if( translate )
|
||||
{
|
||||
glTranslatef(RENDER_IN_SUBPIXEL(m_tAnchorPointInPixels.x), RENDER_IN_SUBPIXEL(m_tAnchorPointInPixels.y), 0);
|
||||
ccglTranslate(RENDER_IN_SUBPIXEL(m_tAnchorPointInPixels.x), RENDER_IN_SUBPIXEL(m_tAnchorPointInPixels.y), 0);
|
||||
}
|
||||
|
||||
m_pCamera->locate();
|
||||
|
||||
if( translate )
|
||||
{
|
||||
glTranslatef(RENDER_IN_SUBPIXEL(-m_tAnchorPointInPixels.x), RENDER_IN_SUBPIXEL(-m_tAnchorPointInPixels.y), 0);
|
||||
ccglTranslate(RENDER_IN_SUBPIXEL(-m_tAnchorPointInPixels.x), RENDER_IN_SUBPIXEL(-m_tAnchorPointInPixels.y), 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -736,8 +799,8 @@ void CCNode::transform()
|
|||
glTranslatef( RENDER_IN_SUBPIXEL(-m_tAnchorPointInPixels.x), RENDER_IN_SUBPIXEL(-m_tAnchorPointInPixels.y), 0);
|
||||
|
||||
if (m_tAnchorPointInPixels.x != 0 || m_tAnchorPointInPixels.y != 0)
|
||||
glTranslatef( RENDER_IN_SUBPIXEL(m_tPosition.x + m_tAnchorPointInPixels.x), RENDER_IN_SUBPIXEL(m_tPosition.y + m_tAnchorPointInPixels.y), m_fVertexZ);
|
||||
else if ( m_tPosition.x !=0 || m_tPosition.y !=0 || m_fVertexZ != 0)
|
||||
glTranslatef( RENDER_IN_SUBPIXEL(m_tPositionInPixels.x + m_tAnchorPointInPixels.x), RENDER_IN_SUBPIXEL(m_tPosition.y + m_tAnchorPointInPixels.y), m_fVertexZ);
|
||||
else if ( m_tPositionInPixels.x !=0 || m_tPositionInPixels.y !=0 || m_fVertexZ != 0)
|
||||
glTranslatef( RENDER_IN_SUBPIXEL(m_tPosition.x), RENDER_IN_SUBPIXEL(m_tPosition.y), m_fVertexZ );
|
||||
|
||||
// rotate
|
||||
|
@ -893,8 +956,8 @@ CGAffineTransform CCNode::nodeToParentTransform(void)
|
|||
if( ! m_bIsRelativeAnchorPoint && ! CGPoint::CGPointEqualToPoint(m_tAnchorPointInPixels, CGPointZero) )
|
||||
m_tTransform = CGAffineTransformTranslate(m_tTransform, m_tAnchorPointInPixels.x, m_tAnchorPointInPixels.y);
|
||||
|
||||
if( ! CGPoint::CGPointEqualToPoint(m_tPosition, CGPointZero) )
|
||||
m_tTransform = CGAffineTransformTranslate(m_tTransform, m_tPosition.x, m_tPosition.y);
|
||||
if( ! CGPoint::CGPointEqualToPoint(m_tPositionInPixels, CGPointZero) )
|
||||
m_tTransform = CGAffineTransformTranslate(m_tTransform, m_tPositionInPixels.x, m_tPosition.y);
|
||||
if( m_fRotation != 0 )
|
||||
m_tTransform = CGAffineTransformRotate(m_tTransform, -CC_DEGREES_TO_RADIANS(m_fRotation));
|
||||
if( ! (m_fScaleX == 1 && m_fScaleY == 1) )
|
||||
|
@ -936,24 +999,68 @@ CGAffineTransform CCNode::worldToNodeTransform(void)
|
|||
|
||||
CGPoint CCNode::convertToNodeSpace(CGPoint worldPoint)
|
||||
{
|
||||
return CGPointApplyAffineTransform(worldPoint, this->worldToNodeTransform());
|
||||
CGPoint ret;
|
||||
if(CC_CONTENT_SCALE_FACTOR() == 1)
|
||||
{
|
||||
ret = CGPointApplyAffineTransform(worldPoint, worldToNodeTransform());
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = ccpMult(worldPoint, CC_CONTENT_SCALE_FACTOR());
|
||||
ret = CGPointApplyAffineTransform(ret, worldToNodeTransform());
|
||||
ret = ccpMult(ret, 1/CC_CONTENT_SCALE_FACTOR());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
CGPoint CCNode::convertToWorldSpace(CGPoint nodePoint)
|
||||
{
|
||||
return CGPointApplyAffineTransform(nodePoint, this->nodeToWorldTransform());
|
||||
CGPoint ret;
|
||||
if(CC_CONTENT_SCALE_FACTOR() == 1)
|
||||
{
|
||||
ret = CGPointApplyAffineTransform(nodePoint, nodeToWorldTransform());
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = ccpMult( nodePoint, CC_CONTENT_SCALE_FACTOR() );
|
||||
ret = CGPointApplyAffineTransform(ret, nodeToWorldTransform());
|
||||
ret = ccpMult( ret, 1/CC_CONTENT_SCALE_FACTOR() );
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
CGPoint CCNode::convertToNodeSpaceAR(CGPoint worldPoint)
|
||||
{
|
||||
CGPoint nodePoint = this->convertToNodeSpace(worldPoint);
|
||||
return ccpSub(nodePoint, m_tAnchorPointInPixels);
|
||||
CGPoint nodePoint = convertToNodeSpace(worldPoint);
|
||||
CGPoint anchorInPoints;
|
||||
if( CC_CONTENT_SCALE_FACTOR() == 1 )
|
||||
{
|
||||
anchorInPoints = m_tAnchorPointInPixels;
|
||||
}
|
||||
else
|
||||
{
|
||||
anchorInPoints = ccpMult( m_tAnchorPointInPixels, 1/CC_CONTENT_SCALE_FACTOR() );
|
||||
}
|
||||
|
||||
return ccpSub(nodePoint, anchorInPoints);
|
||||
}
|
||||
|
||||
CGPoint CCNode::convertToWorldSpaceAR(CGPoint nodePoint)
|
||||
{
|
||||
nodePoint = ccpAdd(nodePoint, m_tAnchorPointInPixels);
|
||||
return this->convertToWorldSpace(nodePoint);
|
||||
CGPoint anchorInPoints;
|
||||
if( CC_CONTENT_SCALE_FACTOR() == 1 )
|
||||
{
|
||||
anchorInPoints = m_tAnchorPointInPixels;
|
||||
}
|
||||
else
|
||||
{
|
||||
anchorInPoints = ccpMult( m_tAnchorPointInPixels, 1/CC_CONTENT_SCALE_FACTOR() );
|
||||
}
|
||||
|
||||
nodePoint = ccpAdd(nodePoint, anchorInPoints);
|
||||
return convertToWorldSpace(nodePoint);
|
||||
}
|
||||
CGPoint CCNode::convertToWindowSpace(CGPoint nodePoint)
|
||||
{
|
File diff suppressed because it is too large
Load Diff
|
@ -240,10 +240,6 @@
|
|||
RelativePath="..\base_nodes\CCAtlasNode.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\base_nodes\CCNode.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="effects"
|
||||
|
@ -896,6 +892,10 @@
|
|||
RelativePath="..\platform\CCFileUtils_platform.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\platform\CCNode_mobile.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\platform\CCXApplication_platform.h"
|
||||
>
|
||||
|
|
Loading…
Reference in New Issue