Merge pull request #9417 from lite3/spriteretainframe

retain the sprite frame in sprite
This commit is contained in:
minggo 2014-12-29 10:33:42 +08:00
commit d7dfdc9124
2 changed files with 11 additions and 0 deletions

View File

@ -264,6 +264,7 @@ Sprite::Sprite(void)
: _batchNode(nullptr)
, _shouldBeHidden(false)
, _texture(nullptr)
, _spriteFrame(nullptr)
, _insideBounds(true)
{
#if CC_SPRITE_DEBUG_DRAW
@ -274,6 +275,7 @@ Sprite::Sprite(void)
Sprite::~Sprite(void)
{
CC_SAFE_RELEASE(_spriteFrame);
CC_SAFE_RELEASE(_texture);
}
@ -936,6 +938,14 @@ void Sprite::setSpriteFrame(const std::string &spriteFrameName)
void Sprite::setSpriteFrame(SpriteFrame *spriteFrame)
{
// retain the sprite frame
// do not removed by SpriteFrameCache::removeUnusedSpriteFrames
if (_spriteFrame != spriteFrame)
{
CC_SAFE_RELEASE(_spriteFrame);
_spriteFrame = spriteFrame;
spriteFrame->retain();
}
_unflippedOffsetPositionFromCenter = spriteFrame->getOffset();
Texture2D *texture = spriteFrame->getTexture();

View File

@ -538,6 +538,7 @@ protected:
//
BlendFunc _blendFunc; /// It's required for TextureProtocol inheritance
Texture2D* _texture; /// Texture2D object that is used to render the sprite
SpriteFrame* _spriteFrame;
QuadCommand _quadCommand; /// quad command
#if CC_SPRITE_DEBUG_DRAW
DrawNode *_debugDrawNode;