cocos2d js-如何删除精灵【原创】

栏目: 编程语言 · IOS · 发布时间: 8年前

内容简介:cocos2d js-如何删除精灵【原创】

最近在项目中遇到一个很棘手的问题,如何在非当前场景中删除精灵。大家都知道,在cocos2d js 中创建精灵、添加精灵是很常见的,删除精灵也是很常见的,删除精灵主要有两种情况:1.在当前方法中删除精灵;2.在非当前场景、当前方法中删除精灵。我研究之后对解决办法整理了下,下面介绍这两种情况如何删除精灵。

第一种情况很简单,怎么添加精灵的就如何删除精灵:

parent.removeChild(child);

第二种情况,删除精灵:

for(var i=0;i<3;i++){

var left_order_bg = new cc.MenuItemImage(
res.goods_bg,
res.goods_bg,
function () {
this.hidden();
GoodsList[i].actionScene();
},
this);
left_order_bg.setScale(0.7);
left_order_bg.setPosition(cc.p(0,-150*i*0.8));
var menu_left_box = new cc.Menu(left_order_bg);
menu_left_box.attr({
x:85,
y:325
})

// 设置标签
menu_left_box.setTag("leftListMenu");

var GoodsName = new cc.LabelTTF(getHotGoodsList_name[i],"Aril",12);
GoodsName.attr({
x:left_order_bg.getContentSize().width/2,
y:40,
color:(51,51,51,125)
});
left_order_bg.addChild(GoodsName);

var GoodImg = new cc.Sprite(getHotGoodsList_img[i]);
GoodImg.attr({
x:left_order_bg.getContentSize().width/2,
y:100,
scale:0.9
});

var GoodsPrice = new cc.LabelTTF(getHotGoodsList_price[i],"Aril",12);
GoodsPrice.attr({
x:left_order_bg.getContentSize().width/2,
y:20,
color:(51,51,51,125)
})

left_order_bg.addChild(GoodImg);
left_order_bg.addChild(GoodsPrice);
_goodsBox.addChild(menu_left_box);
}

hotCallback:function(){
// 删除精灵
_goodsBox.removeChildByTag("leftListMenu");

}

 

第二种情况删除精灵是在添加精灵的时候通过给该精灵添加标签:

// 设置标签
menu_left_box.setTag("leftListMenu");

然后在hotCallback()方法中删除该精灵:

// 删除精灵
_goodsBox.removeChildByTag("leftListMenu");

由于是自己总结的方法,不一定是最好的解决方法,希望能帮助大家解决问题。

本文永久地址:http://blog.it985.com/20614.html

本文出自IT985博客 ,转载时请注明出处及相应链接。


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Mobilizing Web Sites

Mobilizing Web Sites

Layon, Kristofer / 2011-12 / 266.00元

Everyone has been talking about the mobile web in recent years, and more of us are browsing the web on smartphones and similar devices than ever before. But most of what we are viewing has not yet bee......一起来看看 《Mobilizing Web Sites》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

随机密码生成器
随机密码生成器

多种字符组合密码