// Learn cc.Class: // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html // Learn Attribute: // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html cc.Class({ extends: cc.Component, properties: { spritepoint:{ default: null, type: cc.Sprite, }, }, // LIFE-CYCLE CALLBACKS: // onLoad () {}, start () { this.ppos=cc.v2() }, setdata(p,path){ this.player = p; var self = this cc.loader.loadRes(path, cc.SpriteFrame, function (err, res) { if (!err&&self.isValid) { self.spritepoint.spriteFrame = res; } }); this.isfirst = true }, update (dt) { if(this.player){ if(this.player.dead){ this.node.opacity = 0 return } var dx = 0 var dy = 0 var oldx = this.player.x var oldy = this.player.y if(cc.gameMgr.objMap[this.player.player_id] && cc.gameMgr.objMap[this.player.player_id].opacity==255){ // oldx = cc.gameMgr.objMap[this.player.player_id].x // oldy = cc.gameMgr.objMap[this.player.player_id].y // dx = -36 // dy = 36 this.node.opacity = 0 }else{ this.node.opacity = 255 } //this.node.opacity = 255 this.ppos.x = oldx+dx this.ppos.y = oldy+dy let pos1 = cc.gameMgr.ndplayer.convertToWorldSpaceAR(this.ppos); let pos2 = this.node.parent.convertToNodeSpaceAR(pos1); this.node.position = pos2 this.node.x = Math.max(Math.min(cc.winSize.width/2-15,this.node.x),-cc.winSize.width/2+15) this.node.y = Math.max(Math.min(cc.winSize.height/2-15,this.node.y),-cc.winSize.height/2+15) } }, });