Fixing a bug that display is wrong when setting setTexture(NULL) for CCSprite.

This commit is contained in:
James Chen 2013-06-06 14:22:09 +08:00
parent 5c592943db
commit 1a5e9f3717
1 changed files with 10 additions and 2 deletions

View File

@ -153,8 +153,6 @@ bool CCSprite::initWithTexture(CCTexture2D *pTexture, const CCRect& rect, bool r
if (CCNodeRGBA::init()) if (CCNodeRGBA::init())
{ {
m_pobBatchNode = NULL; m_pobBatchNode = NULL;
// shader program
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor));
m_bRecursiveDirty = false; m_bRecursiveDirty = false;
setDirty(false); setDirty(false);
@ -1085,6 +1083,16 @@ void CCSprite::setTexture(CCTexture2D *texture)
// accept texture==nil as argument // accept texture==nil as argument
CCAssert( !texture || dynamic_cast<CCTexture2D*>(texture), "setTexture expects a CCTexture2D. Invalid argument"); CCAssert( !texture || dynamic_cast<CCTexture2D*>(texture), "setTexture expects a CCTexture2D. Invalid argument");
// shader program
if (texture)
{
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor));
}
else
{
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionColor));
}
if (!m_pobBatchNode && m_pobTexture != texture) if (!m_pobBatchNode && m_pobTexture != texture)
{ {
CC_SAFE_RETAIN(texture); CC_SAFE_RETAIN(texture);