🍎这里,我要的效果是点击评论按钮,弹出下面的评论内容节点,然后选择其中一个评论,评论区会新增我选中的这条评论.对于朋友圈内容和回复(
CircleTemple.js
)做成了预制模板,并通过约束对内容的改变高度进行的相应的改变.弹出评论选择的节点是绑定的RepleyScript.js
.🍎首先,对
CircleTemple.js
处理
onCommentHandle:function(){
var _this = this; //防止this改变
var replyLayer = cc.find("Reply").getComponent("ReplyScript");
replyLayer.passValue({layer:_this,id:this.id});
}, //这里将自己和点击的哪个id传过去
在RepleyScript.js
中
properties: {
reply: cc.Node, //这是放置三条评论的节点
label1: cc.Label,
label2:cc.Label,
label3:cc.Label,
content:cc.Node,
content:cc.Node,
fatherLayer:{
default: null,
visible: false,
}
},
onLoad: function () {
this.height = this.reply.height;
this.myData = [{
"coments_id": 1,
"name":"全宇宙最帅的人",
"type": 1, //1代表评论
"contents":"我有一只小毛驴,我从来也不骑,有一天我心血来潮带他去赶集",
},{
"coments_id": 2,
"name":"全宇宙最帅的人",
"type": 1, //1代表评论
"contents":"啊哈哈哈哈哈哈哈",
},{
"coments_id": 3,
"name":"全宇宙最帅的人",
"type": 1, //1代表评论
"contents":"咿咿呀呀噫噫噫",
}
];
this.label1.string = this.myData[0].contents;
this.label2.string = this.myData[1].contents;
this.label3.string = this.myData[2].contents;
},
passValue:function(param){
this.fatherLayer = param.layer;
var actionBy = cc.moveTo(1.0, cc.p(660,this.height/2-20));
this.reply.runAction(actionBy); //这里是弹出动画
},
onBtnClick:function(btn){
var height = this.height -10;
var LocationY = btn.getLocationY();
var num = 0;
if(LocationY<(height)&&LocationY>(2/3*height)){
console.log("第一个按钮");
num = 1;
}
if(LocationY<(2/3*height)&&LocationY>(1/3*height)){
console.log("第二个按钮");
num = 2;
}
if(LocationY<(1/3*height)&&LocationY>0){
console.log("第san个按钮");
num = 3;
}
var actionBy = cc.moveTo(1.0, cc.p(660,-this.height/2));
this.reply.runAction(actionBy);
var data = [];
data.push(this.myData[num-1]);
this.fatherLayer.addPassComments(data);
//这里我们将返回的data传值给CircleTemple.js,直接用fatherLayer调用方法
},
🍎我们再回到CircleTemple.js
中
addPassComments:function(data){
var _this = this;
_this.commentBj.getComponent('CommentLists').addComments(data);
//这里是我将评论区里的每一行的label做成了预制,然后评论有多少就创建多少,通过这个方法,会新增一条评论,将选择的内容展示出来
}
这个方法适用于同场景中切换节点后对切换前后节点状态,以及值的改变进行传递.
以上😝.