From 18c3a8dd022fdd332c75ba32a5cfb1894845335a Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Mon, 24 Feb 2014 15:18:07 -0800 Subject: [PATCH] little fixes for sprite --- cocos/2d/CCSprite.cpp | 36 +++--------------------------------- cocos/2d/CCSprite.h | 4 ++-- 2 files changed, 5 insertions(+), 35 deletions(-) diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index 9a76c6279d..7931e15a3d 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -595,7 +595,7 @@ void Sprite::updateTransform(void) void Sprite::draw(void) { - if(culling()) + if(isInsideBounds()) { _quadCommand.init(_globalZOrder, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, _modelViewTransform); Director::getInstance()->getRenderer()->addCommand(&_quadCommand); @@ -626,7 +626,7 @@ void Sprite::drawDebugData() #endif //CC_SPRITE_DEBUG_DRAW // Culling function from cocos2d-iphone CCSprite.m file -bool Sprite::culling() const +bool Sprite::isInsideBounds() const { // half size of the screen Size screen_half = Director::getInstance()->getWinSize(); @@ -645,15 +645,10 @@ bool Sprite::culling() const y -= screen_half.height; // convert content size to world coordinates -#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 float wchw = hcsx * std::max(fabsf(_modelViewTransform.mat[0] + _modelViewTransform.mat[4]), fabsf(_modelViewTransform.mat[0] - _modelViewTransform.mat[4])); float wchh = hcsy * std::max(fabsf(_modelViewTransform.mat[1] + _modelViewTransform.mat[5]), fabsf(_modelViewTransform.mat[1] - _modelViewTransform.mat[5])); -#else - float wchw = hcsx * fmaxf(fabsf(_modelViewTransform.mat[0] + _modelViewTransform.mat[4]), fabsf(_modelViewTransform.mat[0] - _modelViewTransform.mat[4])); - float wchh = hcsy * fmaxf(fabsf(_modelViewTransform.mat[1] + _modelViewTransform.mat[5]), fabsf(_modelViewTransform.mat[1] - _modelViewTransform.mat[5])); -#endif - // compare if it in the positive quarter of the screen + // compare if it in the positive quadrant of the screen float tmpx = (fabsf(x)-wchw); float tmpy = (fabsf(y)-wchh); return (tmpx < screen_half.width && tmpy < screen_half.height); @@ -725,31 +720,7 @@ void Sprite::sortAllChildren() { if (_reorderChildDirty) { -#if 0 - int i = 0, j = 0, length = _children->count(); - - // insertion sort - for(i=1; i( _children->getObjectAtIndex(i) ); - auto tempJ = static_cast( _children->getObjectAtIndex(j) ); - - //continue moving element downwards while zOrder is smaller or when zOrder is the same but mutatedIndex is smaller - while(j>=0 && ( tempI->getLocalZOrder() < tempJ->getLocalZOrder() || - ( tempI->getLocalZOrder() == tempJ->getLocalZOrder() && - tempI->getOrderOfArrival() < tempJ->getOrderOfArrival() ) ) ) - { - _children->fastSetObject( tempJ, j+1 ); - j = j-1; - if(j>=0) - tempJ = static_cast( _children->getObjectAtIndex(j) ); - } - _children->fastSetObject(tempI, j+1); - } -#else std::sort(std::begin(_children), std::end(_children), nodeComparisonLess); -#endif if ( _batchNode) { @@ -781,7 +752,6 @@ void Sprite::setReorderChildDirtyRecursively(void) } } - void Sprite::setDirtyRecursively(bool bValue) { _recursiveDirty = bValue; diff --git a/cocos/2d/CCSprite.h b/cocos/2d/CCSprite.h index a04f851f16..db96bb871e 100644 --- a/cocos/2d/CCSprite.h +++ b/cocos/2d/CCSprite.h @@ -278,7 +278,7 @@ public: /** * Makes the Sprite to be updated in the Atlas. */ - virtual void setDirty(bool bDirty) { _dirty = bDirty; } + virtual void setDirty(bool dirty) { _dirty = dirty; } /** * Returns the quad (tex coords, vertex coords and color) information. @@ -527,7 +527,7 @@ protected: virtual void setReorderChildDirtyRecursively(void); virtual void setDirtyRecursively(bool bValue); - bool culling() const; + bool isInsideBounds() const; // // Data used when the sprite is rendered using a SpriteSheet