获取节点

this.on = cc.find('Canvas/dianlu/kaiguan/on');

操作节点的属性,opacity、angle等等

this.deng.opacity = 100 + 155*(22.5-this.dianzu)/20;
this.zhizhen.angle = 26 - 32 * (1 - (this.dianzu - 2.5)/20)

事件监听实现的横向拖动

move() {
        //事件监听里的this会绑定为你选择的node,所以用that保存一下
        let that = this;
        this.bopian.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
            // this.opacity = 255;
            var delta = event.touch.getDelta();
            this.x += delta.x;
            // this.y += delta.y;
            //调用that下的方法,此处不能用this
            that.setDianzu();
        }, this.bopian); //第二个参数绑定需要的node节点
    },

修改label的值遇到的坑

不能直接操作label,设置label.string是不起作用的。如下:

var myLabel=cc.find("Canvas/jpmc");
//真正我们需要修改的内容
var labelContent = myLabel.getComponent(cc.Label);
labelContent.string="修改了。。。";

坐标转换`

// 将CurAnswerNode转换成世界坐标然后转到moveNode坐标

const answerWorldPos = curAnswerNode.parent.convertToWorldSpaceAR(curAnswerNode.position); 
const curAnswerPos = this.moveNode.convertToNodeSpaceAR(answerWorldPos);~~~~

张长长
67 声望4 粉丝