-
Creator 版本: 2.4
-
目标平台:
-
重现方式:
-
首个报错:
-
之前哪个版本是正常的:
-
手机型号:
-
手机浏览器:
-
编辑器操作系统:
-
重现概率:
const {ccclass, property} = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
@property
speed = 20;
dir :cc.Vec2[] = [cc.v2(0,0),cc.v2(0,1),cc.v2(1,0),cc.v2(0,-1),cc.v2(-1,0)];
// LIFE-CYCLE CALLBACKS:
onLoad () {
}
start () {
}
update(dt){
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN,function(event){
if (event.keyCode == cc.macro.KEY.w){
console.log("w");
this.node.y += this.speed * dt;
}else if(event.keyCode == cc.macro.KEY.a){
this.node.x -= this.speed *dt;
}else if (event.keyCode == cc.macro.KEY.s){
this.node.y -= this.speed * dt;
}else if (event.keyCode == cc.macro.KEY.d){
this.node.x +=this.speed*dt;
}
})
}
}
终端报错Uncaught TypeError: Cannot read property ‘y’ of undefined,以前直接访问this.node.y 都可以直接设置。为什么这里报错了呢?