diff --git a/cocos2dx/sprite_nodes/CCSprite.cpp b/cocos2dx/sprite_nodes/CCSprite.cpp index b0dea7ca5a..900a2bf97c 100644 --- a/cocos2dx/sprite_nodes/CCSprite.cpp +++ b/cocos2dx/sprite_nodes/CCSprite.cpp @@ -153,8 +153,6 @@ bool CCSprite::initWithTexture(CCTexture2D *pTexture, const CCRect& rect, bool r if (CCNodeRGBA::init()) { m_pobBatchNode = NULL; - // shader program - setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor)); m_bRecursiveDirty = false; setDirty(false); @@ -1085,6 +1083,16 @@ void CCSprite::setTexture(CCTexture2D *texture) // accept texture==nil as argument CCAssert( !texture || dynamic_cast(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) { CC_SAFE_RETAIN(texture);