(Cocos2D_android版)纹理不正常加载,求解!When cocos2D_android loads textures of spirites using multithreading, some errors occured(white rectangle), help me!
在多线程中将文字精灵(CCLabel),加入到当前场景要显示的节点中。结果文字随机的有部分正常显示,有部分不正常显示(显示为白色方块)。开始怀疑是没有加锁造成的,于是锁定对象CCDirector.gl,没有效果。请高人指定迷津。
class panel extends CCNodes{
{
//......
public void reloadSpirites(){
super.clearAllChilds();
new Thread(new Runnable(){
public void run(){addLabels();}
}).start();
}
public void addLabels(){
for(int i = 0; i < 100; i++){
CCLabel name = CCLabel.makeLabel(item.name+i, mFontSize,
TextAlignment.CENTER, "DroidSans", 18);
this.addChild(name);
}
//......
}
问题补充:去掉多线程后,加载很费时,但是纹理加载和显示均没有问题。下图中,上侧为多线程情况,下侧为非多线程正常情况。