萌新请假一个问题!

@property(cc.Node)
man: cc.Node = null;

onLoad () {
    let that=this;
    that.playanim();
    that.node.on(cc.Node.EventType.TOUCH_START, that.touch_start, that.node)
    that.node.on(cc.Node.EventType.TOUCH_END, that.touch_end, that.node)
    
}
//点击事件
touch_start(){
    let seq = cc.moveBy(0.5, 0, this.jump_height);
    this.man.runAction(seq);

//错误提示Uncaught TypeError: Cannot read property ‘runAction’ of undefined。
cc.find(‘Canvas/man’).runAction(seq);//这个就正确!
}

当前脚本是直接挂在canvas上的,节点也拖进去了!这是为什么呢

是这个的问题, 第三个参数是回调函数的this指向,谁调用就是谁。感觉还是没怎么明白

如果你要这样写,最后一个参数改成
that.node.on(cc.Node.EventType.TOUCH_END, that.touch_end, that)

或者可以这样,传两个参数就可以了
that.node.on(cc.Node.EventType.TOUCH_END, that.touch_end.bind(that))

谢谢,刚才 又去看了下JS 的this指向,感觉似懂非懂的!直接在onLoad () {this。touch_start() }里调用 这个touch_start方法其实这个this指的是全局吧?而在on绑定事件里,谁调用this.touch_start那么第三个调用者其实就是this了。

回调事件里的this都是靠绑定才能获得的,必须把that绑定了