Merge pull request #5454 from ricardoquesada/sprite_fixes

little fixes for sprite
This commit is contained in:
Ricardo Quesada 2014-02-24 15:19:04 -08:00
commit 007a1d25b4
2 changed files with 5 additions and 35 deletions

View File

@ -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<length; i++)
{
j = i-1;
auto tempI = static_cast<Node*>( _children->getObjectAtIndex(i) );
auto tempJ = static_cast<Node*>( _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<Node*>( _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;

View File

@ -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