2012-08-23 33 views
1

in Cocos2d-x, 我想反复交换sprite的纹理。Cocos2d-x重复替换纹理

我的交换功能低于...

void GameScene::swapSpriteTexture(CCSprite *a, CCTexture2D *b) 
{ 
    CCTexture2D *tmp = a->getTexture(); 
    a->setTexture(b); 
    b = tmp; 
} 

,我调用该函数链接才可此,

this->swapSpriteTexture(aSprite, m_TextureSlot); 

当我打电话交换功能,第一次,效果很好。
精灵的纹理变化很好。
但是当我再次调用函数时,它不会改变。

m_TextureSlot是

m_TextureSlot=(CCTexture2D *)CCTextureCache::sharedTextureCache()->addImage("smile.png"); 

是这个缓存的问题? 任何想法PLZ ...

回答

1

我的错误...

我改变了这样的功能,

void GameScene::swapSpriteTexture(CCSprite *a, CCTexture2D **b) 
{ 
    CCTexture2D *tmp = a->getTexture(); 
    a->setTexture(*b); 
    *b = tmp; 
} 

和我所说的交换功能。

this->swapSpriteTexture(aSprite, &m_TextureSlot); 

然后,它的工作非常出色。 :)

+0

谢谢,它会在未来帮助我。 –

+0

为什么这个工作和以前不一样? – Wajahat

+0

因为...我们必须改变m_TextureSlot的值,而不是b的值。所以它应该通过引用m_TextureSlot的地址来调用。 –