系统事件-全局事件-键盘和重力传感事件
const {ccclass, property} = cc._decorator;

@ccclass
export default class SysEvent extends cc.Component {

    start () 
    {
        cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN,function(event){
            console.log(event.keyCode + "被按下了")
        })

        cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP,function(event){
            console.log(event.keyCode + "被抬起了")
        })

        cc.systemEvent.on(cc.SystemEvent.EventType.DEVICEMOTION,function(event){
            console.log(event.acc.x + "  " + event.acc.y) //重力传感
        })
    }
}

首页 我的博客
粤ICP备17103704号