cocos studio 加載json文件到場景後重新渲染紋理失敗

如題,由於場景元素多,就用cocos studio搭界面,但是在代碼中想對一張圖片資源做修改時遇到錯誤


Sprite* head_warp=(Sprite*)this->created->getChildByTag(10);

進行判斷後想修改文理,正常調用setTexture(圖片名稱)就可以修改文理

例如:head_warp->setTexture("person_head_0.png");

但是這種方法貌似只支持創建的時候就用圖片名稱創建的才行

後來嘗試

Sprite * aa = Sprite::create("person_head_0.png");
head_warp->setTexture(aa->getTexture());

此方法不報錯,但是無法修改紋理

考慮到cocos studio會不會根本沒有初始化紋理呢

CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage("person_head_0.png");

head_warp->createWithTexture(texture);

還是不行。。。

那就用從圖片獲取紋理後再設置試試

CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage("person_head_0.png");

head_warp->setTexture(texture);

依舊失敗。。。

簡直叫人絕望了,我都想設置這個圖片不可見然後重新創一個了-.-!

要不用ImageView試試,這傢伙不是還有個loadTexture方法麼,不試白不試,畢竟底層代碼看得有點頭大


獲取:ImageView* head_warp=(ImageView*)this->created->getChildByTag(10);

修改:head_warp->loadTexture("person_head_0.png");

居然就這麼好了。。。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章