mirror of https://github.com/axmolengine/axmol.git
Merge pull request #9417 from lite3/spriteretainframe
retain the sprite frame in sprite
This commit is contained in:
commit
d7dfdc9124
|
@ -264,6 +264,7 @@ Sprite::Sprite(void)
|
||||||
: _batchNode(nullptr)
|
: _batchNode(nullptr)
|
||||||
, _shouldBeHidden(false)
|
, _shouldBeHidden(false)
|
||||||
, _texture(nullptr)
|
, _texture(nullptr)
|
||||||
|
, _spriteFrame(nullptr)
|
||||||
, _insideBounds(true)
|
, _insideBounds(true)
|
||||||
{
|
{
|
||||||
#if CC_SPRITE_DEBUG_DRAW
|
#if CC_SPRITE_DEBUG_DRAW
|
||||||
|
@ -274,6 +275,7 @@ Sprite::Sprite(void)
|
||||||
|
|
||||||
Sprite::~Sprite(void)
|
Sprite::~Sprite(void)
|
||||||
{
|
{
|
||||||
|
CC_SAFE_RELEASE(_spriteFrame);
|
||||||
CC_SAFE_RELEASE(_texture);
|
CC_SAFE_RELEASE(_texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -936,6 +938,14 @@ void Sprite::setSpriteFrame(const std::string &spriteFrameName)
|
||||||
|
|
||||||
void Sprite::setSpriteFrame(SpriteFrame *spriteFrame)
|
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();
|
_unflippedOffsetPositionFromCenter = spriteFrame->getOffset();
|
||||||
|
|
||||||
Texture2D *texture = spriteFrame->getTexture();
|
Texture2D *texture = spriteFrame->getTexture();
|
||||||
|
|
|
@ -538,6 +538,7 @@ protected:
|
||||||
//
|
//
|
||||||
BlendFunc _blendFunc; /// It's required for TextureProtocol inheritance
|
BlendFunc _blendFunc; /// It's required for TextureProtocol inheritance
|
||||||
Texture2D* _texture; /// Texture2D object that is used to render the sprite
|
Texture2D* _texture; /// Texture2D object that is used to render the sprite
|
||||||
|
SpriteFrame* _spriteFrame;
|
||||||
QuadCommand _quadCommand; /// quad command
|
QuadCommand _quadCommand; /// quad command
|
||||||
#if CC_SPRITE_DEBUG_DRAW
|
#if CC_SPRITE_DEBUG_DRAW
|
||||||
DrawNode *_debugDrawNode;
|
DrawNode *_debugDrawNode;
|
||||||
|
|
Loading…
Reference in New Issue