cocos-awesome/assets/Scene/Follow_spot/Follow_spot.ts

24 lines
725 B
TypeScript
Raw Permalink Normal View History

2020-04-25 08:07:43 +00:00
const { ccclass, property } = cc._decorator;
@ccclass
export default class Follow_spot extends cc.Component {
@property(cc.Node)
bg: cc.Node = null;
material: cc.Material = null;
2020-04-25 11:09:41 +00:00
center: number[] = [0.1, 0.5];
2020-04-25 08:07:43 +00:00
onLoad() {
this.material = this.bg.getComponent(cc.Sprite).getMaterial(0);
this.material.setProperty('wh_ratio', this.bg.width / this.bg.height);
2020-04-25 11:09:41 +00:00
this.material.setProperty('center', this.center);
2020-04-25 08:07:43 +00:00
2020-04-25 11:09:41 +00:00
this.bg.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoveEvent, this);
2020-04-25 08:07:43 +00:00
}
2020-04-25 11:09:41 +00:00
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);
2020-04-25 08:07:43 +00:00
}
}