mirror of https://github.com/axmolengine/axmol.git
Merge pull request #807 from dumganhar/gles20
issue #1056: Updated SpriteTest.
This commit is contained in:
commit
98ba5ef203
cocos2dx
base_nodes
include
sprite_nodes
tests/tests
|
@ -39,7 +39,7 @@ THE SOFTWARE.
|
||||||
// externals
|
// externals
|
||||||
#include "kazmath/GL/matrix.h"
|
#include "kazmath/GL/matrix.h"
|
||||||
|
|
||||||
#if CC_COCOSNODE_RENDER_SUBPIXEL
|
#if CC_NODE_RENDER_SUBPIXEL
|
||||||
#define RENDER_IN_SUBPIXEL
|
#define RENDER_IN_SUBPIXEL
|
||||||
#else
|
#else
|
||||||
#define RENDER_IN_SUBPIXEL (int)
|
#define RENDER_IN_SUBPIXEL (int)
|
||||||
|
|
|
@ -44,22 +44,23 @@ __arr__++)
|
||||||
I found that it's not work in C++. So it keep what it's look like in version 1.0.0-rc3. ---By Bin
|
I found that it's not work in C++. So it keep what it's look like in version 1.0.0-rc3. ---By Bin
|
||||||
*/
|
*/
|
||||||
#define CCARRAY_FOREACH(__array__, __object__) \
|
#define CCARRAY_FOREACH(__array__, __object__) \
|
||||||
if (__array__ && __array__->data->num > 0) \
|
if ((__array__) && (__array__)->data->num > 0) \
|
||||||
for(CCObject** arr = __array__->data->arr, **end = __array__->data->arr + __array__->data->num-1; \
|
for(CCObject** arr = (__array__)->data->arr, **end = (__array__)->data->arr + (__array__)->data->num-1; \
|
||||||
arr <= end && ((__object__ = *arr) != NULL/* || true*/); \
|
arr <= end && (((__object__) = *arr) != NULL/* || true*/); \
|
||||||
arr++)
|
arr++)
|
||||||
|
|
||||||
#define CCARRAY_FOREACH_REVERSE(__array__, __object__) \
|
#define CCARRAY_FOREACH_REVERSE(__array__, __object__) \
|
||||||
if (__array__ && __array__->data->num > 0) \
|
if ((__array__) && (__array__)->data->num > 0) \
|
||||||
for(CCObject** arr = __array__->data->arr + __array__->data->num-1, **end = __array__->data->arr; \
|
for(CCObject** arr = (__array__)->data->arr + (__array__)->data->num-1, **end = (__array__)->data->arr; \
|
||||||
arr >= end && ((__object__ = *arr) != NULL/* || true*/); \
|
arr >= end && (((__object__) = *arr) != NULL/* || true*/); \
|
||||||
arr--)
|
arr--)
|
||||||
|
|
||||||
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
|
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
|
||||||
#define CCARRAY_VERIFY_TYPE(__array__, __type__) \
|
#define CCARRAY_VERIFY_TYPE(__array__, __type__) \
|
||||||
do { \
|
do { \
|
||||||
if (__array__ && __array__->data->num > 0) \
|
if ((__array__) && (__array__)->data->num > 0) \
|
||||||
for(CCObject** arr = __array__->data->arr, **end = __array__->data->arr + __array__->data->num-1; arr <= end; arr++) \
|
for(CCObject** arr = (__array__)->data->arr, \
|
||||||
|
**end = (__array__)->data->arr + (__array__)->data->num-1; arr <= end; arr++) \
|
||||||
CCAssert(dynamic_cast<__type__>(*arr), "element type is wrong!"); \
|
CCAssert(dynamic_cast<__type__>(*arr), "element type is wrong!"); \
|
||||||
} while(false)
|
} while(false)
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -36,34 +36,35 @@
|
||||||
#include "CCGLProgram.h"
|
#include "CCGLProgram.h"
|
||||||
#include "kazmath/kazmath.h"
|
#include "kazmath/kazmath.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
NS_CC_BEGIN
|
||||||
class CCCamera;
|
|
||||||
class CCGridBase;
|
|
||||||
class CCPoint;
|
|
||||||
class CCTouch;
|
|
||||||
class CCAction;
|
|
||||||
class CCRGBAProtocol;
|
|
||||||
class CCLabelProtocol;
|
|
||||||
class CCScheduler;
|
|
||||||
class CCActionManager;
|
|
||||||
|
|
||||||
enum {
|
class CCCamera;
|
||||||
|
class CCGridBase;
|
||||||
|
class CCPoint;
|
||||||
|
class CCTouch;
|
||||||
|
class CCAction;
|
||||||
|
class CCRGBAProtocol;
|
||||||
|
class CCLabelProtocol;
|
||||||
|
class CCScheduler;
|
||||||
|
class CCActionManager;
|
||||||
|
|
||||||
|
enum {
|
||||||
kCCNodeTagInvalid = -1,
|
kCCNodeTagInvalid = -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
kCCNodeOnEnter,
|
kCCNodeOnEnter,
|
||||||
kCCNodeOnExit
|
kCCNodeOnExit
|
||||||
};
|
};
|
||||||
|
|
||||||
#define arrayMakeObjectsPerformSelectorWithType(pArray, func, type) \
|
#define arrayMakeObjectsPerformSelectorWithType(pArray, func, elementType) \
|
||||||
do { \
|
do { \
|
||||||
if(pArray && pArray->count() > 0) \
|
if(pArray && pArray->count() > 0) \
|
||||||
{ \
|
{ \
|
||||||
CCObject* child; \
|
CCObject* child; \
|
||||||
CCARRAY_FOREACH(pArray, child) \
|
CCARRAY_FOREACH(pArray, child) \
|
||||||
{ \
|
{ \
|
||||||
type* pNode = (type*) child; \
|
elementType pNode = (elementType) child; \
|
||||||
if(pNode && (0 != func)) \
|
if(pNode && (0 != func)) \
|
||||||
{ \
|
{ \
|
||||||
(pNode->*func)(); \
|
(pNode->*func)(); \
|
||||||
|
@ -73,8 +74,24 @@ do { \
|
||||||
} \
|
} \
|
||||||
while(false)
|
while(false)
|
||||||
|
|
||||||
|
#define arrayMakeObjectsPerformSelectorWithObject(pArray, func, pObject, elementType) \
|
||||||
|
do { \
|
||||||
|
if(pArray && pArray->count() > 0) \
|
||||||
|
{ \
|
||||||
|
CCObject* child = NULL; \
|
||||||
|
CCARRAY_FOREACH(pArray, child) \
|
||||||
|
{ \
|
||||||
|
elementType pNode = (elementType) child; \
|
||||||
|
if(pNode && (0 != func)) \
|
||||||
|
{ \
|
||||||
|
(pNode->*func)(pObject); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
while(false)
|
||||||
|
|
||||||
/** @brief CCNode is the main element. Anything thats gets drawn or contains things that get drawn is a CCNode.
|
/** @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 most popular CCNodes are: CCScene, CCLayer, CCSprite, CCMenu.
|
||||||
|
|
||||||
The main features of a CCNode are:
|
The main features of a CCNode are:
|
||||||
|
@ -129,8 +146,8 @@ while(false)
|
||||||
- Each node has a camera. By default it points to the center of the CCNode.
|
- Each node has a camera. By default it points to the center of the CCNode.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class CC_DLL CCNode : public CCObject
|
class CC_DLL CCNode : public CCObject
|
||||||
{
|
{
|
||||||
|
|
||||||
// variable property
|
// variable property
|
||||||
|
|
||||||
|
@ -281,7 +298,7 @@ while(false)
|
||||||
*/
|
*/
|
||||||
CC_PROPERTY(CCScheduler*, m_pScheduler, Scheduler);
|
CC_PROPERTY(CCScheduler*, m_pScheduler, Scheduler);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// transform
|
// transform
|
||||||
CCAffineTransform m_tTransform, m_tInverse;
|
CCAffineTransform m_tTransform, m_tInverse;
|
||||||
|
@ -295,8 +312,7 @@ while(false)
|
||||||
bool m_bReorderChildDirty;
|
bool m_bReorderChildDirty;
|
||||||
int m_nScriptHandler;
|
int m_nScriptHandler;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
//! lazy allocs
|
//! lazy allocs
|
||||||
void childrenAlloc(void);
|
void childrenAlloc(void);
|
||||||
|
|
||||||
|
@ -315,7 +331,7 @@ while(false)
|
||||||
|
|
||||||
CCPoint convertToWindowSpace(const CCPoint& nodePoint);
|
CCPoint convertToWindowSpace(const CCPoint& nodePoint);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
CCNode(void);
|
CCNode(void);
|
||||||
|
|
||||||
|
@ -618,8 +634,9 @@ while(false)
|
||||||
@since v0.7.1
|
@since v0.7.1
|
||||||
*/
|
*/
|
||||||
CCPoint convertTouchToNodeSpaceAR(CCTouch * touch);
|
CCPoint convertTouchToNodeSpaceAR(CCTouch * touch);
|
||||||
};
|
};
|
||||||
}//namespace cocos2d
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
#endif // __PLATFOMR_CCNODE_H__
|
#endif // __PLATFOMR_CCNODE_H__
|
||||||
|
|
||||||
|
|
|
@ -155,6 +155,9 @@ public:
|
||||||
*/
|
*/
|
||||||
static CCSprite* spriteWithFile(const char *pszFileName, const CCRect& rect);
|
static CCSprite* spriteWithFile(const char *pszFileName, const CCRect& rect);
|
||||||
|
|
||||||
|
/** Creates an sprite.
|
||||||
|
*/
|
||||||
|
static CCSprite* node();
|
||||||
public:
|
public:
|
||||||
CCSprite(void);
|
CCSprite(void);
|
||||||
virtual ~CCSprite(void);
|
virtual ~CCSprite(void);
|
||||||
|
@ -213,74 +216,74 @@ public:
|
||||||
The rect used will be the size of the texture.
|
The rect used will be the size of the texture.
|
||||||
The offset will be (0,0).
|
The offset will be (0,0).
|
||||||
*/
|
*/
|
||||||
bool initWithTexture(CCTexture2D *pTexture);
|
virtual bool initWithTexture(CCTexture2D *pTexture);
|
||||||
|
|
||||||
/** Initializes an sprite with a texture and a rect.
|
/** Initializes an sprite with a texture and a rect.
|
||||||
The offset will be (0,0).
|
The offset will be (0,0).
|
||||||
*/
|
*/
|
||||||
bool initWithTexture(CCTexture2D *pTexture, const CCRect& rect);
|
virtual bool initWithTexture(CCTexture2D *pTexture, const CCRect& rect);
|
||||||
|
|
||||||
/** Initializes an sprite with a texture and a rect in points, optionally rotated.
|
/** Initializes an sprite with a texture and a rect in points, optionally rotated.
|
||||||
The offset will be (0,0).
|
The offset will be (0,0).
|
||||||
IMPORTANT: This is the designated initializer.
|
IMPORTANT: This is the designated initializer.
|
||||||
*/
|
*/
|
||||||
bool initWithTexture(CCTexture2D *pTexture, const CCRect& rect, bool rotated);
|
virtual bool initWithTexture(CCTexture2D *pTexture, const CCRect& rect, bool rotated);
|
||||||
|
|
||||||
// Initializes an sprite with an sprite frame.
|
// Initializes an sprite with an sprite frame.
|
||||||
bool initWithSpriteFrame(CCSpriteFrame *pSpriteFrame);
|
virtual bool initWithSpriteFrame(CCSpriteFrame *pSpriteFrame);
|
||||||
|
|
||||||
/** Initializes an sprite with an sprite frame name.
|
/** Initializes an sprite with an sprite frame name.
|
||||||
An CCSpriteFrame will be fetched from the CCSpriteFrameCache by name.
|
An CCSpriteFrame will be fetched from the CCSpriteFrameCache by name.
|
||||||
If the CCSpriteFrame doesn't exist it will raise an exception.
|
If the CCSpriteFrame doesn't exist it will raise an exception.
|
||||||
@since v0.9
|
@since v0.9
|
||||||
*/
|
*/
|
||||||
bool initWithSpriteFrameName(const char *pszSpriteFrameName);
|
virtual bool initWithSpriteFrameName(const char *pszSpriteFrameName);
|
||||||
|
|
||||||
/** Initializes an sprite with an image filename.
|
/** Initializes an sprite with an image filename.
|
||||||
The rect used will be the size of the image.
|
The rect used will be the size of the image.
|
||||||
The offset will be (0,0).
|
The offset will be (0,0).
|
||||||
*/
|
*/
|
||||||
bool initWithFile(const char *pszFilename);
|
virtual bool initWithFile(const char *pszFilename);
|
||||||
|
|
||||||
/** Initializes an sprite with an image filename, and a rect.
|
/** Initializes an sprite with an image filename, and a rect.
|
||||||
The offset will be (0,0).
|
The offset will be (0,0).
|
||||||
*/
|
*/
|
||||||
bool initWithFile(const char *pszFilename, const CCRect& rect);
|
virtual bool initWithFile(const char *pszFilename, const CCRect& rect);
|
||||||
|
|
||||||
// BatchNode methods
|
// BatchNode methods
|
||||||
|
|
||||||
/** updates the quad according the the rotation, position, scale values. */
|
/** updates the quad according the the rotation, position, scale values. */
|
||||||
void updateTransform(void);
|
virtual void updateTransform(void);
|
||||||
|
|
||||||
/** updates the texture rect of the CCSprite in points.
|
/** updates the texture rect of the CCSprite in points.
|
||||||
It will call setTextureRect:rotated:untrimmedSize with rotated = NO, and utrimmedSize = rect.size.
|
It will call setTextureRect:rotated:untrimmedSize with rotated = NO, and utrimmedSize = rect.size.
|
||||||
*/
|
*/
|
||||||
void setTextureRect(const CCRect& rect);
|
virtual void setTextureRect(const CCRect& rect);
|
||||||
|
|
||||||
/** set the texture rect, rectRotated and untrimmed size of the CCSprite in points.
|
/** set the texture rect, rectRotated and untrimmed size of the CCSprite in points.
|
||||||
It will update the texture coordinates and the vertex rectangle.
|
It will update the texture coordinates and the vertex rectangle.
|
||||||
*/
|
*/
|
||||||
void setTextureRect(const CCRect& rect, bool rotated, const CCSize& untrimmedSize);
|
virtual void setTextureRect(const CCRect& rect, bool rotated, const CCSize& untrimmedSize);
|
||||||
|
|
||||||
/** set the vertex rect.
|
/** set the vertex rect.
|
||||||
It will be called internally by setTextureRect. Useful if you want to create 2x images from SD images in Retina Display.
|
It will be called internally by setTextureRect. Useful if you want to create 2x images from SD images in Retina Display.
|
||||||
Do not call it manually. Use setTextureRect instead.
|
Do not call it manually. Use setTextureRect instead.
|
||||||
*/
|
*/
|
||||||
void setVertexRect(const CCRect& rect);
|
virtual void setVertexRect(const CCRect& rect);
|
||||||
|
|
||||||
// Frames
|
// Frames
|
||||||
|
|
||||||
/** sets a new display frame to the CCSprite. */
|
/** sets a new display frame to the CCSprite. */
|
||||||
void setDisplayFrame(CCSpriteFrame *pNewFrame);
|
virtual void setDisplayFrame(CCSpriteFrame *pNewFrame);
|
||||||
|
|
||||||
/** returns whether or not a CCSpriteFrame is being displayed */
|
/** returns whether or not a CCSpriteFrame is being displayed */
|
||||||
bool isFrameDisplayed(CCSpriteFrame *pFrame);
|
virtual bool isFrameDisplayed(CCSpriteFrame *pFrame);
|
||||||
|
|
||||||
/** returns the current displayed frame. */
|
/** returns the current displayed frame. */
|
||||||
CCSpriteFrame* displayFrame(void);
|
virtual CCSpriteFrame* displayFrame(void);
|
||||||
|
|
||||||
CCSpriteBatchNode* getBatchNode(void);
|
virtual CCSpriteBatchNode* getBatchNode(void);
|
||||||
void setBatchNode(CCSpriteBatchNode *pobSpriteBatchNode);
|
virtual void setBatchNode(CCSpriteBatchNode *pobSpriteBatchNode);
|
||||||
|
|
||||||
// Animation
|
// Animation
|
||||||
|
|
||||||
|
@ -288,7 +291,7 @@ public:
|
||||||
The animation name will be get from the CCAnimationCache
|
The animation name will be get from the CCAnimationCache
|
||||||
@since v0.99.5
|
@since v0.99.5
|
||||||
*/
|
*/
|
||||||
void setDisplayFrameWithAnimationName(const char *animationName, int frameIndex);
|
virtual void setDisplayFrameWithAnimationName(const char *animationName, int frameIndex);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void setTextureCoords(CCRect rect);
|
virtual void setTextureCoords(CCRect rect);
|
||||||
|
|
|
@ -216,8 +216,6 @@ void CCAnimationCache::addAnimationsWithDictionary(CCDictionary* dictionary)
|
||||||
if( properties )
|
if( properties )
|
||||||
{
|
{
|
||||||
version = atoi(valueForKey("format", properties));
|
version = atoi(valueForKey("format", properties));
|
||||||
}
|
|
||||||
|
|
||||||
CCArray* spritesheets = (CCArray*)properties->objectForKey("spritesheets");
|
CCArray* spritesheets = (CCArray*)properties->objectForKey("spritesheets");
|
||||||
|
|
||||||
CCObject* pObj = NULL;
|
CCObject* pObj = NULL;
|
||||||
|
@ -226,6 +224,7 @@ void CCAnimationCache::addAnimationsWithDictionary(CCDictionary* dictionary)
|
||||||
CCString* name = (CCString*)(pObj);
|
CCString* name = (CCString*)(pObj);
|
||||||
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(name->c_str());
|
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(name->c_str());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (version) {
|
switch (version) {
|
||||||
case 1:
|
case 1:
|
||||||
|
|
|
@ -137,6 +137,20 @@ CCSprite* CCSprite::spriteWithSpriteFrameName(const char *pszSpriteFrameName)
|
||||||
return spriteWithSpriteFrame(pFrame);
|
return spriteWithSpriteFrame(pFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CCSprite* CCSprite::node()
|
||||||
|
{
|
||||||
|
CCSprite *pSprite = new CCSprite();
|
||||||
|
if (pSprite && pSprite->init())
|
||||||
|
{
|
||||||
|
pSprite->autorelease();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CC_SAFE_DELETE(pSprite);
|
||||||
|
}
|
||||||
|
return pSprite;
|
||||||
|
}
|
||||||
|
|
||||||
bool CCSprite::init(void)
|
bool CCSprite::init(void)
|
||||||
{
|
{
|
||||||
return initWithTexture(NULL, CCRectZero);
|
return initWithTexture(NULL, CCRectZero);
|
||||||
|
@ -505,7 +519,7 @@ void CCSprite::updateTransform(void)
|
||||||
|
|
||||||
// recursively iterate over children
|
// recursively iterate over children
|
||||||
if( m_bHasChildren ) {
|
if( m_bHasChildren ) {
|
||||||
arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCSprite::updateTransform, CCSprite);
|
arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCSprite::updateTransform, CCSprite*);
|
||||||
}
|
}
|
||||||
#if CC_SPRITE_DEBUG_DRAW
|
#if CC_SPRITE_DEBUG_DRAW
|
||||||
// draw bounding box
|
// draw bounding box
|
||||||
|
@ -701,7 +715,7 @@ void CCSprite::sortAllChildren()
|
||||||
|
|
||||||
if ( m_pobBatchNode)
|
if ( m_pobBatchNode)
|
||||||
{
|
{
|
||||||
arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCSprite::sortAllChildren, CCSprite);
|
arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCSprite::sortAllChildren, CCSprite*);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_bReorderChildDirty = false;
|
m_bReorderChildDirty = false;
|
||||||
|
|
|
@ -98,10 +98,12 @@ bool CCSpriteBatchNode::initWithTexture(CCTexture2D *tex, unsigned int capacity)
|
||||||
updateBlendFunc();
|
updateBlendFunc();
|
||||||
|
|
||||||
// no lazy alloc in this node
|
// no lazy alloc in this node
|
||||||
m_pChildren = CCArray::array();
|
m_pChildren = new CCArray();
|
||||||
m_pobDescendants = CCArray::array();
|
m_pChildren->initWithCapacity(capacity);
|
||||||
m_pChildren->retain();
|
|
||||||
m_pobDescendants->retain();
|
m_pobDescendants = new CCArray();
|
||||||
|
m_pobDescendants->initWithCapacity(capacity);
|
||||||
|
|
||||||
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor));
|
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -169,10 +171,10 @@ void CCSpriteBatchNode::visit(void)
|
||||||
void CCSpriteBatchNode::addChild(CCNode *child, int zOrder, int tag)
|
void CCSpriteBatchNode::addChild(CCNode *child, int zOrder, int tag)
|
||||||
{
|
{
|
||||||
CCAssert(child != NULL, "child should not be null");
|
CCAssert(child != NULL, "child should not be null");
|
||||||
|
CCAssert(dynamic_cast<CCSprite*>(child) != NULL, "CCSpriteBatchNode only supports CCSprites as children");
|
||||||
CCSprite *pSprite = (CCSprite*)(child);
|
CCSprite *pSprite = (CCSprite*)(child);
|
||||||
// check CCSprite is using the same texture id
|
// check CCSprite is using the same texture id
|
||||||
CCAssert(pSprite->getTexture()->getName() == m_pobTextureAtlas->getTexture()->getName(), "");
|
CCAssert(pSprite->getTexture()->getName() == m_pobTextureAtlas->getTexture()->getName(), "CCSprite is not using the same texture id");
|
||||||
|
|
||||||
CCNode::addChild(child, zOrder, tag);
|
CCNode::addChild(child, zOrder, tag);
|
||||||
|
|
||||||
|
@ -231,18 +233,7 @@ void CCSpriteBatchNode::removeChildAtIndex(unsigned int uIndex, bool bDoCleanup)
|
||||||
void CCSpriteBatchNode::removeAllChildrenWithCleanup(bool bCleanup)
|
void CCSpriteBatchNode::removeAllChildrenWithCleanup(bool bCleanup)
|
||||||
{
|
{
|
||||||
// Invalidate atlas index. issue #569
|
// Invalidate atlas index. issue #569
|
||||||
if (m_pChildren && m_pChildren->count() > 0)
|
arrayMakeObjectsPerformSelectorWithObject(m_pobDescendants, &CCSprite::setBatchNode, NULL, CCSprite*);
|
||||||
{
|
|
||||||
CCObject* pObject = NULL;
|
|
||||||
CCARRAY_FOREACH(m_pChildren, pObject)
|
|
||||||
{
|
|
||||||
CCSprite* pChild = (CCSprite*) pObject;
|
|
||||||
if (pChild)
|
|
||||||
{
|
|
||||||
removeSpriteFromAtlas(pChild);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CCNode::removeAllChildrenWithCleanup(bCleanup);
|
CCNode::removeAllChildrenWithCleanup(bCleanup);
|
||||||
|
|
||||||
|
@ -280,7 +271,7 @@ void CCSpriteBatchNode::sortAllChildren()
|
||||||
if (m_pChildren->count() > 0)
|
if (m_pChildren->count() > 0)
|
||||||
{
|
{
|
||||||
//first sort all children recursively based on zOrder
|
//first sort all children recursively based on zOrder
|
||||||
arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCSprite::sortAllChildren, CCSprite);
|
arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCSprite::sortAllChildren, CCSprite*);
|
||||||
|
|
||||||
int index=0;
|
int index=0;
|
||||||
|
|
||||||
|
@ -403,7 +394,7 @@ void CCSpriteBatchNode::draw(void)
|
||||||
|
|
||||||
CC_NODE_DRAW_SETUP();
|
CC_NODE_DRAW_SETUP();
|
||||||
|
|
||||||
arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCSprite::updateTransform, CCSprite);
|
arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCSprite::updateTransform, CCSprite*);
|
||||||
|
|
||||||
ccGLBlendFunc( m_blendFunc.src, m_blendFunc.dst );
|
ccGLBlendFunc( m_blendFunc.src, m_blendFunc.dst );
|
||||||
|
|
||||||
|
@ -561,56 +552,40 @@ unsigned int CCSpriteBatchNode::atlasIndexForChild(CCSprite *pobSprite, int nZ)
|
||||||
|
|
||||||
// add child helper
|
// add child helper
|
||||||
|
|
||||||
void CCSpriteBatchNode::insertChild(CCSprite *pobSprite, unsigned int uIndex)
|
void CCSpriteBatchNode::insertChild(CCSprite *pSprite, unsigned int uIndex)
|
||||||
{
|
{
|
||||||
pobSprite->setBatchNode(this);
|
pSprite->setBatchNode(this);
|
||||||
pobSprite->setAtlasIndex(uIndex);
|
pSprite->setAtlasIndex(uIndex);
|
||||||
pobSprite->setDirty(true);
|
pSprite->setDirty(true);
|
||||||
|
|
||||||
if (m_pobTextureAtlas->getTotalQuads() == m_pobTextureAtlas->getCapacity())
|
if(m_pobTextureAtlas->getTotalQuads() == m_pobTextureAtlas->getCapacity())
|
||||||
{
|
{
|
||||||
increaseAtlasCapacity();
|
increaseAtlasCapacity();
|
||||||
}
|
}
|
||||||
|
|
||||||
ccV3F_C4B_T2F_Quad quad = pobSprite->getQuad();
|
ccV3F_C4B_T2F_Quad quad = pSprite->getQuad();
|
||||||
m_pobTextureAtlas->insertQuad(&quad, uIndex);
|
m_pobTextureAtlas->insertQuad(&quad, uIndex);
|
||||||
|
|
||||||
m_pobDescendants->insertObject(pobSprite, uIndex);
|
ccArray *descendantsData = m_pobDescendants->data;
|
||||||
|
|
||||||
|
ccArrayInsertObjectAtIndex(descendantsData, pSprite, uIndex);
|
||||||
|
|
||||||
// update indices
|
// update indices
|
||||||
unsigned int i = 0;
|
unsigned int i = uIndex+1;
|
||||||
if (m_pobDescendants && m_pobDescendants->count() > 0)
|
|
||||||
{
|
CCSprite* pChild = NULL;
|
||||||
CCObject* pObject = NULL;
|
for(; i<descendantsData->num; i++){
|
||||||
CCARRAY_FOREACH(m_pobDescendants, pObject)
|
pChild = (CCSprite*)descendantsData->arr[i];
|
||||||
{
|
|
||||||
CCSprite* pChild = (CCSprite*) pObject;
|
|
||||||
if (pChild)
|
|
||||||
{
|
|
||||||
if (i > uIndex)
|
|
||||||
{
|
|
||||||
pChild->setAtlasIndex(pChild->getAtlasIndex() + 1);
|
pChild->setAtlasIndex(pChild->getAtlasIndex() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// add children recursively
|
// add children recursively
|
||||||
CCArray *pChildren = pobSprite->getChildren();
|
CCObject* pObj = NULL;
|
||||||
if (pChildren && pChildren->count() > 0)
|
CCARRAY_FOREACH(pSprite->getChildren(), pObj)
|
||||||
{
|
{
|
||||||
CCObject* pObject = NULL;
|
pChild = (CCSprite*)pObj;
|
||||||
CCARRAY_FOREACH(pChildren, pObject)
|
unsigned int idx = atlasIndexForChild(pChild, pChild->getZOrder());
|
||||||
{
|
insertChild(pChild, idx);
|
||||||
CCSprite* pChild = (CCSprite*) pObject;
|
|
||||||
if (pChild)
|
|
||||||
{
|
|
||||||
unsigned int uIndex = atlasIndexForChild(pChild, pChild->getZOrder());
|
|
||||||
insertChild(pChild, uIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -754,8 +729,7 @@ CCSpriteBatchNode * CCSpriteBatchNode::addSpriteWithoutQuad(CCSprite*child, unsi
|
||||||
|
|
||||||
// XXX: optimize with a binary search
|
// XXX: optimize with a binary search
|
||||||
int i=0;
|
int i=0;
|
||||||
if (m_pobDescendants && m_pobDescendants->count() > 0)
|
|
||||||
{
|
|
||||||
CCObject* pObject = NULL;
|
CCObject* pObject = NULL;
|
||||||
CCARRAY_FOREACH(m_pobDescendants, pObject)
|
CCARRAY_FOREACH(m_pobDescendants, pObject)
|
||||||
{
|
{
|
||||||
|
@ -765,7 +739,7 @@ CCSpriteBatchNode * CCSpriteBatchNode::addSpriteWithoutQuad(CCSprite*child, unsi
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
m_pobDescendants->insertObject(child, i);
|
m_pobDescendants->insertObject(child, i);
|
||||||
|
|
||||||
// IMPORTANT: Call super, and not self. Avoid adding it to the texture atlas array
|
// IMPORTANT: Call super, and not self. Avoid adding it to the texture atlas array
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
20e32b9a1ad61e6bf3e179cc5e1cd7d7bdec57fa
|
45fa60a7892453b6d2be3554738d829d7743303e
|
|
@ -483,7 +483,6 @@ public:
|
||||||
SpriteBatchNodeReorderOneChild();
|
SpriteBatchNodeReorderOneChild();
|
||||||
void reorderSprite(ccTime dt);
|
void reorderSprite(ccTime dt);
|
||||||
virtual std::string title();
|
virtual std::string title();
|
||||||
virtual std::string subtitle();
|
|
||||||
private:
|
private:
|
||||||
CCSpriteBatchNode *m_pBatchNode;
|
CCSpriteBatchNode *m_pBatchNode;
|
||||||
CCSprite *m_pReorderSprite;
|
CCSprite *m_pReorderSprite;
|
||||||
|
|
|
@ -805,7 +805,7 @@ TMXIsoZorder::TMXIsoZorder()
|
||||||
addChild(map, 0, kTagTileMap);
|
addChild(map, 0, kTagTileMap);
|
||||||
|
|
||||||
CCSize s = map->getContentSize();
|
CCSize s = map->getContentSize();
|
||||||
////----UXLOG("ContentSize: %f, %f", s.width,s.height);
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
||||||
map->setPosition(ccp(-s.width/2,0));
|
map->setPosition(ccp(-s.width/2,0));
|
||||||
|
|
||||||
m_tamara = CCSprite::spriteWithFile(s_pPathSister1);
|
m_tamara = CCSprite::spriteWithFile(s_pPathSister1);
|
||||||
|
@ -1011,7 +1011,7 @@ TMXOrthoVertexZ::TMXOrthoVertexZ()
|
||||||
// can use any CCSprite and it will work OK.
|
// can use any CCSprite and it will work OK.
|
||||||
CCTMXLayer* layer = map->layerNamed("trees");
|
CCTMXLayer* layer = map->layerNamed("trees");
|
||||||
m_tamara = layer->tileAt(ccp(0,11));
|
m_tamara = layer->tileAt(ccp(0,11));
|
||||||
CCLOG("%@ vertexZ: %f", m_tamara, m_tamara->getVertexZ());
|
CCLOG("%p vertexZ: %f", m_tamara, m_tamara->getVertexZ());
|
||||||
m_tamara->retain();
|
m_tamara->retain();
|
||||||
|
|
||||||
CCActionInterval* move = CCMoveBy::actionWithDuration(10, ccpMult( ccp(400,450), 1/CC_CONTENT_SCALE_FACTOR()));
|
CCActionInterval* move = CCMoveBy::actionWithDuration(10, ccpMult( ccp(400,450), 1/CC_CONTENT_SCALE_FACTOR()));
|
||||||
|
|
Loading…
Reference in New Issue