Cocos Creator零基础小白超神教程

- cc鼠标事件监听:
// 鼠标按下
this.node.on(cc.Node.EventType.MOUSE_DOWN, function(event) {
console.debug('坐标:'+ event.getLocation())
})
// MOUSE_MOVE
// MOUSE_LEAVA
// MOUSE_UP
- 判断左右键
if(event.getButton() == cc.Event.EventMouse.BUTTON_RIGHT) {
console.debug('按下右键')
}
- 去掉监听事件
this.node.off(cc.Node.EventType.MOUSE_DOWN)
- 监听键盘
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWM, function(event){
if (event.keyCode === cc.macro.KEY.w)
console.debug('按下w键')
})
- 碰撞检测
cc.director.getCollisionManager().enabled = true;
// 产生碰撞
onCollisionEnter(other){
console.debug('碰撞开始' + other.tag)
}
onCollisionStay(other){
console.debug('碰撞持续')
}
onCollisionExit(other){
console.debug('碰撞结束')
}