将预制件进行big数组中的对应加载,出现的每一个根据传来的type值进行对应的加载因为
//agentia脚本里调用这个方法并且分开传递过来每一个的背包数据
pub_Thenext:function(ob){
//复制保存数组
this._data = ob
var that = this
that._addSpriteFrameToContainer(that.node.getChildByName('drugSprite').getComponent(cc.Sprite), "pic/locn/"+GameData.propArr[ob.type].pic);
that.node.getChildByName("drugLabel").getComponent(cc.Label).string = ob.num
//添加点击事件
that.node.getChildByName('drugSprite').on(cc.Node.EventType.TOUCH_START,function(){
that.choose()
})
that.accept()
that.subscript()
},
},
然后进行点击事件后调用choose方法将之前定好位false的全局变量取反,然后把隐藏的选中框显示出来,然后抛出一个自定义事件,自定义事件包含现在这个点击的预制件的背包ID,
choose:function(){
this.pitch = !this.pitch
this.node.getChildByName('pitchOn').active = this.pitch
//如果是这个脚本的第一次点击则抛出一个自定义事件并且将这个脚本的背包ID和type值抛出
if(this.pitch){
var proptypeId = new cc.Event.EventCustom(GameEvent.propAction, false)
proptypeId.setUserData([this._data.BagID,this._data.type]);
cc.find('UIscript').dispatchEvent(proptypeId);
}
},
然后在这个方法里接收背包ID,因为是捆绑在预制件上的脚本所以这个脚本的事件是一个预制件抛出多个预制件进行接收,接收后开始比对自身的背包ID和传来的背包ID,如果相等就不管,如果不相等而且全局变量为选中的状态,那么就让这个脚本调用choose方法进行选中的框隐藏。
//接收自定义事件并且取得背包ID
accept:function(){
var that = this;
var node = cc.find("UIscript")
node.on(GameEvent.propAction,function(event){
var data = event.getUserData()[0]
//进行点击传来的type的脚本本身的一个type值比较如果不同并且是第一次点击该道具则调用choose方法
if(data != that._data.BagID && that.pitch){
that.choose()
}
})
},