12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- cc.Class({
- extends: cc.Component,
- properties: {
- content: cc.Node,
- _lastLocation: null,
- },
- onLoad() {
- this.node.on(cc.Node.EventType.TOUCH_MOVE, (event) => {
- if (this._lastLocation === null) {
- this._lastLocation = event.getStartLocation();
- }
- let currentLocation = event.getLocation();
- let moveY = currentLocation.y - this._lastLocation.y;
- let moveX = currentLocation.x - this._lastLocation.x;
- let sin = moveY / moveX;
- if (sin >= 1 || sin <= -1) {
- let durationY = currentLocation.y - this._lastLocation.y;
- this.content.y = this.content.y + durationY;
- if (this.content.y <= this.node.height / 2) {
- this.content.y = this.node.height / 2;
- } else if (this.content.y >= this.content.height - this.node.height / 2) {
- this.content.y = this.content.height - this.node.height / 2;
- }
- this._lastLocation = currentLocation;
- }
- }, this);
- this.node.on(cc.Node.EventType.TOUCH_END, (event) => {
- this._lastLocation = null;
- });
- this.node.on(cc.Node.EventType.TOUCH_CANCEL, (event) => {
- this._lastLocation = null;
- });
- },
- start() {
- },
- // update (dt) {},
- });
|