Cocos2d-x中对Sprite进行setTexture时,调用SpriteBatchNode对象时需要注意的问题

一个单独的A类,继承自Sprite类,因为某些原因需要重新setTexture,并且是SpriteBatchNode的对象,本以为是个小改,没想到重新运行后什么图像都没了……

重新找了一下原因,发现Sprite的createWithTexture方法中,在initWithTexture方法最后里面不仅setTexture,还setTextureRect。HOHO,原来是这个原因,所以光针对Sprite去setTexture还不够,还需要在后面补充一个setTextureRect才可以。


	SpriteBatchNode* BatchNode = SpriteBatchNode::create("a.png",10000);
	for (Index; Index < 10000; Index++)
	{
		A* pA = A::create();
<span style="white-space: pre;">		</span>pA->setTexture(BatchNode->getTexture());
		Rect _rect = Rect::ZERO;
		_rect.size = BatchNode->getTexture()->getContentSize();
		pA->setTextureRect(_rect);
		pA->setPosition(100,i);
<span style="white-space:pre">		</span>this->addChild(pA);
	}


你可能感兴趣的:(cocos2d-x,SpriteBatchNode,setTexture)