import Global from "./Global"; const { ccclass, property } = cc._decorator; @ccclass export default class Playcontroler extends cc.Component { // LIFE-CYCLE CALLBACKS: // parent:cc.Node = null; MainScene: cc.Component = null; onLoad() { cc.game.setFrameRate(59) // this.parent = this.node.parent; this.MainScene = Global.instance.getMN(); } start() { } update(dt) { if (Global.instance.OverFlag) { this.enabled = false; } else { if (!Global.instance.CollisionFlag) { this.node.y -= Global.instance.InitSpeed; } else { let name = Global.instance.TheHolder.name; if (name == "") { return; } this.node.y = Global.instance.TheHolder.y + Global.instance.TheHolder.getComponent(name).NodeH - 5;//here ,this way isnot a good Processing method,should be optimizated } } if (Global.instance.CollisionWithDing) { this.node.stopAllActions(); Global.instance.CollisionWithDing = false; Global.instance.CollisionFlag = false; } } /** * player与墙壁的碰撞检测 * @param other 被撞物体 * @param self 碰撞体 */ onCollisionEnter(other, self) { let rootSelf = this; switch (other.node.name) { case "Bg_0CollisionR": { self.node.x = 180; break; } case "Bg_0CollisionL": { self.node.x = -180; break; } case "Bg_1CollisionR": { self.node.x = 180; break; } case "Bg_1CollisionL": { self.node.x = -180; break; } // case "tanhuang":{ // if(other.node.x+75>self.node.x&&other.node.x-75