加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Cocos2d-x中对Sprite进行setTexture时,调用SpriteBatchNode对象

发布时间:2020-12-14 21:45:28 所属栏目:百科 来源:网络整理
导读:一个单独的A类,继承自Sprite类,因为某些原因需要重新setTexture,并且是SpriteBatchNode的对象,本以为是个小改,没想到重新运行后什么图像都没了…… 重新找了一下原因,发现Sprite的createWithTexture方法中,在initWithTexture方法最后里面不仅setTextu

一个单独的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);
	}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读