1// 判断是不是移动平台 2cc.sys.isMobile 3 4 5// 动画系统 6this.anim = this.getComponent(cc.Animation) as cc.Animation; 7 8 9// 全场最佳 唯一 ,跨场景存活 10cc.game.addPersistRootNode(this.node); 11 12 13// 监听按键事件 14cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this) 15cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this) 16 17// 注销按键事件 18cc.systemEvent.off(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this); 19cc.systemEvent.off(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this); 20 21/** 22 * 键盘弹起事件 23 * @param event 24 */ 25onKeyUp(event: KeyboardEvent){ ... } 26 27 28// 监听触摸移动事件 29this.node.on(cc.Node.EventType.TOUCH_MOVE, this.onMove, this); 30// 注销触摸移动事件 31this.node.off(cc.Node.EventType.TOUCH_MOVE, this.onMove, this); 32 33/** 34 * 移动设备,手指移动,玩家飞机跟着跑 35 */ 36onMove(event: cc.Event.EventTouch) { 37 this.node.position = event.getLocation() 38} 39 40 41// 开启碰撞检测 42let manager = cc.director.getCollisionManager(); 43manager.enabled = true; 44// 碰撞检测系统的 debug 绘制 45manager.enabledDebugDraw = true; 46 47/** 48 * 碰撞事件发生时 49 * @param other 对方节点 50 * @param self 自己的节点 51 */ 52onCollisionEnter(other: cc.Collider, self: cc.Collider) { 53 // 如果是敌机,或者敌机的子弹,直接boom,结算积分嘲讽一波 54 if (!this.HAS_BOOM && (other.node.group == 'b_enemy' || other.node.group == 'enemy')) { 55 this.HAS_BOOM = true; 56 this.boom(); 57 } 58} 59 60 61// 界面跳转 62cc.director.loadScene('launch');
Cocos笔记
Stella981
2021-10-11
923 0 0
点赞
收藏
评论区
加载中...