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
|
@ -39,7 +39,7 @@ THE SOFTWARE.
|
|||
// externals
|
||||
#include "kazmath/GL/matrix.h"
|
||||
|
||||
#if CC_COCOSNODE_RENDER_SUBPIXEL
|
||||
#if CC_NODE_RENDER_SUBPIXEL
|
||||
#define RENDER_IN_SUBPIXEL
|
||||
#else
|
||||
#define RENDER_IN_SUBPIXEL (int)
|
||||
|
|
|
@ -43,24 +43,25 @@ __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
|
||||
*/
|
||||
#define CCARRAY_FOREACH(__array__, __object__) \
|
||||
if (__array__ && __array__->data->num > 0) \
|
||||
for(CCObject** arr = __array__->data->arr, **end = __array__->data->arr + __array__->data->num-1; \
|
||||
arr <= end && ((__object__ = *arr) != NULL/* || true*/); \
|
||||
#define CCARRAY_FOREACH(__array__, __object__) \
|
||||
if ((__array__) && (__array__)->data->num > 0) \
|
||||
for(CCObject** arr = (__array__)->data->arr, **end = (__array__)->data->arr + (__array__)->data->num-1; \
|
||||
arr <= end && (((__object__) = *arr) != NULL/* || true*/); \
|
||||
arr++)
|
||||
|
||||
#define CCARRAY_FOREACH_REVERSE(__array__, __object__) \
|
||||
if (__array__ && __array__->data->num > 0) \
|
||||
for(CCObject** arr = __array__->data->arr + __array__->data->num-1, **end = __array__->data->arr; \
|
||||
arr >= end && ((__object__ = *arr) != NULL/* || true*/); \
|
||||
#define CCARRAY_FOREACH_REVERSE(__array__, __object__) \
|
||||
if ((__array__) && (__array__)->data->num > 0) \
|
||||
for(CCObject** arr = (__array__)->data->arr + (__array__)->data->num-1, **end = (__array__)->data->arr; \
|
||||
arr >= end && (((__object__) = *arr) != NULL/* || true*/); \
|
||||
arr--)
|
||||
|
||||
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
|
||||
#define CCARRAY_VERIFY_TYPE(__array__, __type__) \
|
||||
do { \
|
||||
if (__array__ && __array__->data->num > 0) \
|
||||
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!"); \
|
||||
#define CCARRAY_VERIFY_TYPE(__array__, __type__) \
|
||||
do { \
|
||||
if ((__array__) && (__array__)->data->num > 0) \
|
||||
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!"); \
|
||||
} while(false)
|
||||
#else
|
||||
#define CCARRAY_VERIFY_TYPE(__array__, __type__) void(0)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -155,6 +155,9 @@ public:
|
|||
*/
|
||||
static CCSprite* spriteWithFile(const char *pszFileName, const CCRect& rect);
|
||||
|
||||
/** Creates an sprite.
|
||||
*/
|
||||
static CCSprite* node();
|
||||
public:
|
||||
CCSprite(void);
|
||||
virtual ~CCSprite(void);
|
||||
|
@ -213,74 +216,74 @@ public:
|
|||
The rect used will be the size of the texture.
|
||||
The offset will be (0,0).
|
||||
*/
|
||||
bool initWithTexture(CCTexture2D *pTexture);
|
||||
virtual bool initWithTexture(CCTexture2D *pTexture);
|
||||
|
||||
/** Initializes an sprite with a texture and a rect.
|
||||
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.
|
||||
The offset will be (0,0).
|
||||
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.
|
||||
bool initWithSpriteFrame(CCSpriteFrame *pSpriteFrame);
|
||||
virtual bool initWithSpriteFrame(CCSpriteFrame *pSpriteFrame);
|
||||
|
||||
/** Initializes an sprite with an sprite frame name.
|
||||
An CCSpriteFrame will be fetched from the CCSpriteFrameCache by name.
|
||||
If the CCSpriteFrame doesn't exist it will raise an exception.
|
||||
@since v0.9
|
||||
*/
|
||||
bool initWithSpriteFrameName(const char *pszSpriteFrameName);
|
||||
virtual bool initWithSpriteFrameName(const char *pszSpriteFrameName);
|
||||
|
||||
/** Initializes an sprite with an image filename.
|
||||
The rect used will be the size of the image.
|
||||
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.
|
||||
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
|
||||
|
||||
/** 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.
|
||||
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.
|
||||
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.
|
||||
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.
|
||||
*/
|
||||
void setVertexRect(const CCRect& rect);
|
||||
virtual void setVertexRect(const CCRect& rect);
|
||||
|
||||
// Frames
|
||||
|
||||
/** 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 */
|
||||
bool isFrameDisplayed(CCSpriteFrame *pFrame);
|
||||
virtual bool isFrameDisplayed(CCSpriteFrame *pFrame);
|
||||
|
||||
/** returns the current displayed frame. */
|
||||
CCSpriteFrame* displayFrame(void);
|
||||
virtual CCSpriteFrame* displayFrame(void);
|
||||
|
||||
CCSpriteBatchNode* getBatchNode(void);
|
||||
void setBatchNode(CCSpriteBatchNode *pobSpriteBatchNode);
|
||||
virtual CCSpriteBatchNode* getBatchNode(void);
|
||||
virtual void setBatchNode(CCSpriteBatchNode *pobSpriteBatchNode);
|
||||
|
||||
// Animation
|
||||
|
||||
|
@ -288,7 +291,7 @@ public:
|
|||
The animation name will be get from the CCAnimationCache
|
||||
@since v0.99.5
|
||||
*/
|
||||
void setDisplayFrameWithAnimationName(const char *animationName, int frameIndex);
|
||||
virtual void setDisplayFrameWithAnimationName(const char *animationName, int frameIndex);
|
||||
|
||||
protected:
|
||||
virtual void setTextureCoords(CCRect rect);
|
||||
|
|
|
@ -216,15 +216,14 @@ void CCAnimationCache::addAnimationsWithDictionary(CCDictionary* dictionary)
|
|||
if( properties )
|
||||
{
|
||||
version = atoi(valueForKey("format", properties));
|
||||
}
|
||||
CCArray* spritesheets = (CCArray*)properties->objectForKey("spritesheets");
|
||||
|
||||
CCArray* spritesheets = (CCArray*)properties->objectForKey("spritesheets");
|
||||
|
||||
CCObject* pObj = NULL;
|
||||
CCARRAY_FOREACH(spritesheets, pObj)
|
||||
{
|
||||
CCString* name = (CCString*)(pObj);
|
||||
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(name->c_str());
|
||||
CCObject* pObj = NULL;
|
||||
CCARRAY_FOREACH(spritesheets, pObj)
|
||||
{
|
||||
CCString* name = (CCString*)(pObj);
|
||||
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(name->c_str());
|
||||
}
|
||||
}
|
||||
|
||||
switch (version) {
|
||||
|
|
|
@ -137,6 +137,20 @@ CCSprite* CCSprite::spriteWithSpriteFrameName(const char *pszSpriteFrameName)
|
|||
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)
|
||||
{
|
||||
return initWithTexture(NULL, CCRectZero);
|
||||
|
@ -505,7 +519,7 @@ void CCSprite::updateTransform(void)
|
|||
|
||||
// recursively iterate over children
|
||||
if( m_bHasChildren ) {
|
||||
arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCSprite::updateTransform, CCSprite);
|
||||
arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCSprite::updateTransform, CCSprite*);
|
||||
}
|
||||
#if CC_SPRITE_DEBUG_DRAW
|
||||
// draw bounding box
|
||||
|
@ -701,7 +715,7 @@ void CCSprite::sortAllChildren()
|
|||
|
||||
if ( m_pobBatchNode)
|
||||
{
|
||||
arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCSprite::sortAllChildren, CCSprite);
|
||||
arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCSprite::sortAllChildren, CCSprite*);
|
||||
}
|
||||
|
||||
m_bReorderChildDirty = false;
|
||||
|
|
|
@ -98,10 +98,12 @@ bool CCSpriteBatchNode::initWithTexture(CCTexture2D *tex, unsigned int capacity)
|
|||
updateBlendFunc();
|
||||
|
||||
// no lazy alloc in this node
|
||||
m_pChildren = CCArray::array();
|
||||
m_pobDescendants = CCArray::array();
|
||||
m_pChildren->retain();
|
||||
m_pobDescendants->retain();
|
||||
m_pChildren = new CCArray();
|
||||
m_pChildren->initWithCapacity(capacity);
|
||||
|
||||
m_pobDescendants = new CCArray();
|
||||
m_pobDescendants->initWithCapacity(capacity);
|
||||
|
||||
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor));
|
||||
return true;
|
||||
}
|
||||
|
@ -169,10 +171,10 @@ void CCSpriteBatchNode::visit(void)
|
|||
void CCSpriteBatchNode::addChild(CCNode *child, int zOrder, int tag)
|
||||
{
|
||||
CCAssert(child != NULL, "child should not be null");
|
||||
|
||||
CCAssert(dynamic_cast<CCSprite*>(child) != NULL, "CCSpriteBatchNode only supports CCSprites as children");
|
||||
CCSprite *pSprite = (CCSprite*)(child);
|
||||
// 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);
|
||||
|
||||
|
@ -231,18 +233,7 @@ void CCSpriteBatchNode::removeChildAtIndex(unsigned int uIndex, bool bDoCleanup)
|
|||
void CCSpriteBatchNode::removeAllChildrenWithCleanup(bool bCleanup)
|
||||
{
|
||||
// Invalidate atlas index. issue #569
|
||||
if (m_pChildren && m_pChildren->count() > 0)
|
||||
{
|
||||
CCObject* pObject = NULL;
|
||||
CCARRAY_FOREACH(m_pChildren, pObject)
|
||||
{
|
||||
CCSprite* pChild = (CCSprite*) pObject;
|
||||
if (pChild)
|
||||
{
|
||||
removeSpriteFromAtlas(pChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
arrayMakeObjectsPerformSelectorWithObject(m_pobDescendants, &CCSprite::setBatchNode, NULL, CCSprite*);
|
||||
|
||||
CCNode::removeAllChildrenWithCleanup(bCleanup);
|
||||
|
||||
|
@ -280,7 +271,7 @@ void CCSpriteBatchNode::sortAllChildren()
|
|||
if (m_pChildren->count() > 0)
|
||||
{
|
||||
//first sort all children recursively based on zOrder
|
||||
arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCSprite::sortAllChildren, CCSprite);
|
||||
arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCSprite::sortAllChildren, CCSprite*);
|
||||
|
||||
int index=0;
|
||||
|
||||
|
@ -403,7 +394,7 @@ void CCSpriteBatchNode::draw(void)
|
|||
|
||||
CC_NODE_DRAW_SETUP();
|
||||
|
||||
arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCSprite::updateTransform, CCSprite);
|
||||
arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCSprite::updateTransform, CCSprite*);
|
||||
|
||||
ccGLBlendFunc( m_blendFunc.src, m_blendFunc.dst );
|
||||
|
||||
|
@ -561,57 +552,41 @@ unsigned int CCSpriteBatchNode::atlasIndexForChild(CCSprite *pobSprite, int nZ)
|
|||
|
||||
// add child helper
|
||||
|
||||
void CCSpriteBatchNode::insertChild(CCSprite *pobSprite, unsigned int uIndex)
|
||||
void CCSpriteBatchNode::insertChild(CCSprite *pSprite, unsigned int uIndex)
|
||||
{
|
||||
pobSprite->setBatchNode(this);
|
||||
pobSprite->setAtlasIndex(uIndex);
|
||||
pobSprite->setDirty(true);
|
||||
pSprite->setBatchNode(this);
|
||||
pSprite->setAtlasIndex(uIndex);
|
||||
pSprite->setDirty(true);
|
||||
|
||||
if (m_pobTextureAtlas->getTotalQuads() == m_pobTextureAtlas->getCapacity())
|
||||
{
|
||||
increaseAtlasCapacity();
|
||||
}
|
||||
if(m_pobTextureAtlas->getTotalQuads() == m_pobTextureAtlas->getCapacity())
|
||||
{
|
||||
increaseAtlasCapacity();
|
||||
}
|
||||
|
||||
ccV3F_C4B_T2F_Quad quad = pobSprite->getQuad();
|
||||
m_pobTextureAtlas->insertQuad(&quad, uIndex);
|
||||
ccV3F_C4B_T2F_Quad quad = pSprite->getQuad();
|
||||
m_pobTextureAtlas->insertQuad(&quad, uIndex);
|
||||
|
||||
m_pobDescendants->insertObject(pobSprite, uIndex);
|
||||
ccArray *descendantsData = m_pobDescendants->data;
|
||||
|
||||
// update indices
|
||||
unsigned int i = 0;
|
||||
if (m_pobDescendants && m_pobDescendants->count() > 0)
|
||||
{
|
||||
CCObject* pObject = NULL;
|
||||
CCARRAY_FOREACH(m_pobDescendants, pObject)
|
||||
{
|
||||
CCSprite* pChild = (CCSprite*) pObject;
|
||||
if (pChild)
|
||||
{
|
||||
if (i > uIndex)
|
||||
{
|
||||
pChild->setAtlasIndex(pChild->getAtlasIndex() + 1);
|
||||
}
|
||||
ccArrayInsertObjectAtIndex(descendantsData, pSprite, uIndex);
|
||||
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
// update indices
|
||||
unsigned int i = uIndex+1;
|
||||
|
||||
// add children recursively
|
||||
CCArray *pChildren = pobSprite->getChildren();
|
||||
if (pChildren && pChildren->count() > 0)
|
||||
{
|
||||
CCObject* pObject = NULL;
|
||||
CCARRAY_FOREACH(pChildren, pObject)
|
||||
{
|
||||
CCSprite* pChild = (CCSprite*) pObject;
|
||||
if (pChild)
|
||||
{
|
||||
unsigned int uIndex = atlasIndexForChild(pChild, pChild->getZOrder());
|
||||
insertChild(pChild, uIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
CCSprite* pChild = NULL;
|
||||
for(; i<descendantsData->num; i++){
|
||||
pChild = (CCSprite*)descendantsData->arr[i];
|
||||
pChild->setAtlasIndex(pChild->getAtlasIndex() + 1);
|
||||
}
|
||||
|
||||
// add children recursively
|
||||
CCObject* pObj = NULL;
|
||||
CCARRAY_FOREACH(pSprite->getChildren(), pObj)
|
||||
{
|
||||
pChild = (CCSprite*)pObj;
|
||||
unsigned int idx = atlasIndexForChild(pChild, pChild->getZOrder());
|
||||
insertChild(pChild, idx);
|
||||
}
|
||||
}
|
||||
|
||||
// addChild helper, faster than insertChild
|
||||
|
@ -754,18 +729,17 @@ CCSpriteBatchNode * CCSpriteBatchNode::addSpriteWithoutQuad(CCSprite*child, unsi
|
|||
|
||||
// XXX: optimize with a binary search
|
||||
int i=0;
|
||||
if (m_pobDescendants && m_pobDescendants->count() > 0)
|
||||
|
||||
CCObject* pObject = NULL;
|
||||
CCARRAY_FOREACH(m_pobDescendants, pObject)
|
||||
{
|
||||
CCObject* pObject = NULL;
|
||||
CCARRAY_FOREACH(m_pobDescendants, pObject)
|
||||
CCSprite* pChild = (CCSprite*) pObject;
|
||||
if (pChild && (pChild->getAtlasIndex() >= z))
|
||||
{
|
||||
CCSprite* pChild = (CCSprite*) pObject;
|
||||
if (pChild && (pChild->getAtlasIndex() >= z))
|
||||
{
|
||||
++i;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
m_pobDescendants->insertObject(child, i);
|
||||
|
||||
// IMPORTANT: Call super, and not self. Avoid adding it to the texture atlas array
|
||||
|
|
|
@ -1 +1 @@
|
|||
20e32b9a1ad61e6bf3e179cc5e1cd7d7bdec57fa
|
||||
45fa60a7892453b6d2be3554738d829d7743303e
|
|
@ -483,7 +483,6 @@ public:
|
|||
SpriteBatchNodeReorderOneChild();
|
||||
void reorderSprite(ccTime dt);
|
||||
virtual std::string title();
|
||||
virtual std::string subtitle();
|
||||
private:
|
||||
CCSpriteBatchNode *m_pBatchNode;
|
||||
CCSprite *m_pReorderSprite;
|
||||
|
|
|
@ -805,7 +805,7 @@ TMXIsoZorder::TMXIsoZorder()
|
|||
addChild(map, 0, kTagTileMap);
|
||||
|
||||
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));
|
||||
|
||||
m_tamara = CCSprite::spriteWithFile(s_pPathSister1);
|
||||
|
@ -1011,7 +1011,7 @@ TMXOrthoVertexZ::TMXOrthoVertexZ()
|
|||
// can use any CCSprite and it will work OK.
|
||||
CCTMXLayer* layer = map->layerNamed("trees");
|
||||
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();
|
||||
|
||||
CCActionInterval* move = CCMoveBy::actionWithDuration(10, ccpMult( ccp(400,450), 1/CC_CONTENT_SCALE_FACTOR()));
|
||||
|
|
Loading…
Reference in New Issue