mirror of
https://github.com/ifengzp/cocos-awesome.git
synced 2024-12-25 11:19:16 +00:00
调整追光的触控方式
This commit is contained in:
parent
6dcd1c406b
commit
f513a759c1
@ -5,19 +5,19 @@ export default class Follow_spot extends cc.Component {
|
|||||||
@property(cc.Node)
|
@property(cc.Node)
|
||||||
bg: cc.Node = null;
|
bg: cc.Node = null;
|
||||||
material: cc.Material = null;
|
material: cc.Material = null;
|
||||||
|
center: number[] = [0.1, 0.5];
|
||||||
|
|
||||||
onLoad() {
|
onLoad() {
|
||||||
this.material = this.bg.getComponent(cc.Sprite).getMaterial(0);
|
this.material = this.bg.getComponent(cc.Sprite).getMaterial(0);
|
||||||
this.material.setProperty('wh_ratio', this.bg.width / this.bg.height);
|
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_MOVE, this.touchMoveEvent, this);
|
||||||
this.bg.on(cc.Node.EventType.TOUCH_START, this.touchEvent, this);
|
|
||||||
this.bg.on(cc.Node.EventType.TOUCH_MOVE, this.touchEvent, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
touchEvent(evt: cc.Event.EventTouch) {
|
touchMoveEvent(evt: cc.Event.EventTouch) {
|
||||||
let pos = evt.getLocation();
|
this.center[0] += evt.getDeltaX() / this.bg.width;
|
||||||
this.material.setProperty('center', [pos.x / this.bg.width, (this.bg.height - pos.y) / this.bg.height]);
|
this.center[1] -= evt.getDeltaY() / this.bg.height;
|
||||||
|
this.material.setProperty('center', this.center);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user