不太懂 在for里 给超过五个左右sprite设置 position就无响应?
有哪位能告诉我怎么解决吗 或者你们对于100多个sprite是怎么做的?
楼主能否提供下测试代码呢。 仅仅设置position是不会导致卡顿的。
for(var i=0; i<100; i++){
var sp = new cc.Sprite(res.CloseNormal_png);
this.addChild(sp);
sp.setPosition(cc.p(i+5i,i+5i));
}
刚测试了下,木有问题。楼主提供代码看看吧
var LLKSprite=cc.Sprite.extend({
_no:0,
_status:0,
_width:10,
_height:0,
_textTureMe:"",
/* w 1-9 h 1-12
*
* x int no of pic
* z int status of pic 0 normal 1 boom 2 stone
*
*/
ctor:function(x,z,w,h){
var item={
bow:"res/wow/Weapon/Bow/INV_Weapon_Bow_",//12
axe:"res/wow/Weapon/Axe/INV_Axe_",//26
crossbow:"res/wow/Weapon/Crossbow/INV_Weapon_Crossbow_",//11
throwingaxe:"res/wow/Weapon/ThrowingAxe/INV_ThrowingAxe_",//6
staff:"res/wow/Weapon/Staff/INV_Staff_"//36
//total 91
};
//根据lv 选取几种图标
this._textTureMe=x<=12?item'bow']+(x>9?x:("0"+x))+'.jpg':(x<=38?item'axe']+(x-12>9?x-12:("0"+(x-12)))+'.jpg':(x<=49?item'crossbow']+(x-38>9?x-38:("0"+(x-38)))+'.jpg':(x<=55?item'throwingaxe']+(x-49>9?x-49:("0"+(x-49)))+'.jpg':(x<=91?item'staff']+(x-55>9?x-55:("0"+(x-55)))+'.jpg':null))));
this._super(this._textTureMe);
this._no=x;
this._width=w*64;
this._height=h*64;
this._status=z>=0&&z<=2?x:0;
if(this._status==1){
this.setOpacity(199);
this.updateDisplayedColor(cc.color(255,102,102,255));
this.setOpacityModifyRGB(true);
}else if(this._status==2){
this.setOpacity(155);
this.updateDisplayedColor(cc.color(204,153,153,255));
this.setOpacityModifyRGB(true);
}
this.setPosition(this._width,this._height);
// this.scheduleOnce(this.onInitPosition,0.1);
},
onInitPosition:function(){
if(this._status==1){
this.setOpacity(199);
this.updateDisplayedColor(cc.color(255,102,102,255));
this.setOpacityModifyRGB(true);
}else if(this._status==2){
this.setOpacity(155);
this.updateDisplayedColor(cc.color(204,153,153,255));
this.setOpacityModifyRGB(true);
}
this.setPosition(this._width,this._height);
}
});
是我继承sprite的缘故吗 其他的就是for循环
你是onInitPosition 和 setposition形成死循环了吧,你可以断点看看卡在哪里。
已经好了
我把图片弄成plist了 用cc.Sprite.createWithSpriteFrame 创建就 会报错了。
发现是我数组取越界了。。。 生成的文件名字符串是 undefined
改了之后就好了
3q 热心回答
好的。谢谢反馈。