// Learn cc.Class: // - [Chinese] http://www.cocos.com/docs/creator/scripting/class.html // - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/class/index.html // Learn Attribute: // - [Chinese] http://www.cocos.com/docs/creator/scripting/reference/attributes.html // - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/reference/attributes/index.html // Learn life-cycle callbacks: // - [Chinese] http://www.cocos.com/docs/creator/scripting/life-cycle-callbacks.html // - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/life-cycle-callbacks/index.html cc.Class({ extends: cc.Component, properties: { target: { default: null, type: cc.Node }, lastUpdateTargerPosY:0 }, // use this for initialization onLoad: function () { this.camera = this.getComponent(cc.Camera); }, onEnable: function () { // cc.director.getPhysicsManager().attachDebugDrawToCamera(this.camera); //cc.director.getCollisionManager().attachDebugDrawToCamera(this.camera); }, onDisable: function () { // cc.director.getPhysicsManager().detachDebugDrawFromCamera(this.camera); //cc.director.getCollisionManager().detachDebugDrawFromCamera(this.camera); }, resetData: function() { this.lastUpdateTargerPosY = 0; }, // called every frame, uncomment this function to activate update callback lateUpdate: function (dt) { //let targetPos = this.target.convertToWorldSpaceAR(cc.Vec2.ZERO); //this.node.position = this.node.convertToNodeSpaceAR(targetPos); var isUp = true; if (this.target.position.y > 0) { if (this.target.position.y - this.lastUpdateTargerPosY > 0) { this.lastUpdateTargerPosY = this.target.position.y; } else { isUp = false; } } if (isUp && this.target.position.y > 0) { this.node.position = this.target.position; } // let ratio = targetPos.y / cc.winSize.height; // this.camera.zoomRatio = 1 + (0.5 - ratio) * 0.5; }, });