From f513a759c18674af0ccce37e0707a7c3aa5718db Mon Sep 17 00:00:00 2001 From: ifengzp Date: Sat, 25 Apr 2020 19:09:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=BF=BD=E5=85=89=E7=9A=84?= =?UTF-8?q?=E8=A7=A6=E6=8E=A7=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/Scene/Follow_spot/Follow_spot.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/assets/Scene/Follow_spot/Follow_spot.ts b/assets/Scene/Follow_spot/Follow_spot.ts index 7e6b22c..ec33fb5 100644 --- a/assets/Scene/Follow_spot/Follow_spot.ts +++ b/assets/Scene/Follow_spot/Follow_spot.ts @@ -5,19 +5,19 @@ export default class Follow_spot extends cc.Component { @property(cc.Node) bg: cc.Node = null; material: cc.Material = null; + center: number[] = [0.1, 0.5]; onLoad() { this.material = this.bg.getComponent(cc.Sprite).getMaterial(0); this.material.setProperty('wh_ratio', this.bg.width / this.bg.height); - console.log(this.bg.width / this.bg.height) + this.material.setProperty('center', this.center); - - this.bg.on(cc.Node.EventType.TOUCH_START, this.touchEvent, this); - this.bg.on(cc.Node.EventType.TOUCH_MOVE, this.touchEvent, this); + this.bg.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoveEvent, this); } - touchEvent(evt: cc.Event.EventTouch) { - let pos = evt.getLocation(); - this.material.setProperty('center', [pos.x / this.bg.width, (this.bg.height - pos.y) / this.bg.height]); + touchMoveEvent(evt: cc.Event.EventTouch) { + this.center[0] += evt.getDeltaX() / this.bg.width; + this.center[1] -= evt.getDeltaY() / this.bg.height; + this.material.setProperty('center', this.center); } }