欢迎光临散文网 会员登陆 & 注册

Cocos Creator零基础小白超神教程

2023-09-05 10:58 作者:前端叭叭说  | 我要投稿
  • 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('碰撞结束')

}


Cocos Creator零基础小白超神教程的评论 (共 条)

分享到微博请遵守国家法律