Skip to content

Commit

Permalink
Merge pull request cocos2d#3065 from dumganhar/iss2359-ccontrolswitch
Browse files Browse the repository at this point in the history
Sprite will become white block when using CCControlSwitch.
setShaderProgram should not be in Sprite::setTexture since setTexture is not related to shader.
  • Loading branch information
James Chen committed Jul 3, 2013
2 parents 331c688 + 501afdd commit b441871
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions cocos2dx/sprite_nodes/CCSprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,16 @@ bool Sprite::initWithTexture(Texture2D *pTexture, const Rect& rect, bool rotated
_quad.tl.colors = tmpColor;
_quad.tr.colors = tmpColor;

// shader program
if (pTexture)
{
setShaderProgram(ShaderCache::sharedShaderCache()->programForKey(kShader_PositionTextureColor));
}
else
{
setShaderProgram(ShaderCache::sharedShaderCache()->programForKey(kShader_PositionColor));
}

// update texture (calls updateBlendFunc)
setTexture(pTexture);
setTextureRect(rect, rotated, rect.size);
Expand Down Expand Up @@ -1081,16 +1091,6 @@ void Sprite::setTexture(Texture2D *texture)
CCAssert(! _batchNode || texture->getName() == _batchNode->getTexture()->getName(), "CCSprite: Batched sprites should use the same texture as the batchnode");
// accept texture==nil as argument
CCAssert( !texture || dynamic_cast<Texture2D*>(texture), "setTexture expects a Texture2D. Invalid argument");

// shader program
if (texture)
{
setShaderProgram(ShaderCache::sharedShaderCache()->programForKey(kShader_PositionTextureColor));
}
else
{
setShaderProgram(ShaderCache::sharedShaderCache()->programForKey(kShader_PositionColor));
}

if (!_batchNode && _texture != texture)
{
Expand Down

0 comments on commit b441871

Please sign in to comment.