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);
	}

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...