Cocos Creator零基礎(chǔ)小白超神教程

- cc鼠標(biāo)事件監(jiān)聽:
// 鼠標(biāo)按下
this.node.on(cc.Node.EventType.MOUSE_DOWN, function(event) {
console.debug('坐標(biāo):'+ event.getLocation())
})
// MOUSE_MOVE
// MOUSE_LEAVA
// MOUSE_UP
- 判斷左右鍵
if(event.getButton() == cc.Event.EventMouse.BUTTON_RIGHT) {
console.debug('按下右鍵')
}
- 去掉監(jiān)聽事件
this.node.off(cc.Node.EventType.MOUSE_DOWN)
- 監(jiān)聽鍵盤
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWM, function(event){
if (event.keyCode === cc.macro.KEY.w)
console.debug('按下w鍵')
})
- 碰撞檢測(cè)
cc.director.getCollisionManager().enabled = true;
// 產(chǎn)生碰撞
onCollisionEnter(other){
console.debug('碰撞開始' + other.tag)
}
onCollisionStay(other){
console.debug('碰撞持續(xù)')
}
onCollisionExit(other){
console.debug('碰撞結(jié)束')
}
標(biāo)簽: