Explorar el Código

Z字飘落动画组件添加,代码优化

薛鸿潇 hace 5 años
padre
commit
0cc45f5db6

+ 10 - 10
mk_framework/assets/script/game/component/tween/ClickMoveBy.ts

@@ -26,7 +26,7 @@ export default class ClickMoveBy extends cc.Component {
     /** 是否要返回 */
     /** 是否要返回 */
     is_back: boolean = false;
     is_back: boolean = false;
     onLoad() {
     onLoad() {
-        this.node.on('click', this.StartMoveBy, this)
+        this.node.on('click', this.StartMoveBy, this);
     }
     }
 
 
     start() {
     start() {
@@ -39,20 +39,20 @@ export default class ClickMoveBy extends cc.Component {
      */
      */
     StartMoveBy() {
     StartMoveBy() {
         if (this.state === StateType.moving) return;
         if (this.state === StateType.moving) return;
-        let next_state = 0
-        let temp_vec_move = cc.Vec2.ZERO
+        let next_state = 0;
+        let temp_vec_move = cc.Vec2.ZERO;
         if (this.state === StateType.out) {
         if (this.state === StateType.out) {
-            temp_vec_move = this.vec_move
-            next_state = StateType.back
+            temp_vec_move = this.vec_move;
+            next_state = StateType.back;
         } else if (this.state === StateType.back) {
         } else if (this.state === StateType.back) {
-            temp_vec_move.x = -this.vec_move.x
-            temp_vec_move.y = -this.vec_move.y
-            next_state = StateType.out
+            temp_vec_move.x = -this.vec_move.x;
+            temp_vec_move.y = -this.vec_move.y;
+            next_state = StateType.out;
         }
         }
-        this.state = StateType.moving
+        this.state = StateType.moving;
         let move1 = cc.tween().by(0.5, { position: { value: temp_vec_move, easing: 'backOut' } })
         let move1 = cc.tween().by(0.5, { position: { value: temp_vec_move, easing: 'backOut' } })
         let call1 = cc.tween().call(() => {
         let call1 = cc.tween().call(() => {
-            this.state = next_state
+            this.state = next_state;
         })
         })
         cc.tween(this.node).then(move1).then(call1).start();
         cc.tween(this.node).then(move1).then(call1).start();
     }
     }

+ 7 - 7
mk_framework/assets/script/game/component/tween/RopeSwung.ts

@@ -34,10 +34,10 @@ export default class RopeSwung extends cc.Component {
     start() {
     start() {
         if (CC_EDITOR) {
         if (CC_EDITOR) {
             if (this.edit_play) {
             if (this.edit_play) {
-                this.initShakeSlow()
+                this.initShakeSlow();
             }
             }
         } else {
         } else {
-            this.initShakeSlow()
+            this.initShakeSlow();
         }
         }
     }
     }
     /**
     /**
@@ -46,11 +46,11 @@ export default class RopeSwung extends cc.Component {
      */
      */
     private initShakeSlow() {
     private initShakeSlow() {
         let node = this.node;
         let node = this.node;
-        let rotate1 = cc.tween().to(this.time, { angle: { value: this.angle, easing: 'sineOut' } })
-        let rotate2 = cc.tween().to(this.time, { angle: { value: 0, easing: 'sineIn' } })
-        let rotate3 = cc.tween().to(this.time, { angle: { value: -this.angle, easing: 'sineOut' } })
-        let rotate4 = cc.tween().to(this.time, { angle: { value: 0, easing: 'sineIn' } })
-        let sequence1 = cc.tween().sequence(rotate1, rotate2, rotate3, rotate4)
+        let rotate1 = cc.tween().to(this.time, { angle: { value: this.angle, easing: 'sineOut' } });
+        let rotate2 = cc.tween().to(this.time, { angle: { value: 0, easing: 'sineIn' } });
+        let rotate3 = cc.tween().to(this.time, { angle: { value: -this.angle, easing: 'sineOut' } });
+        let rotate4 = cc.tween().to(this.time, { angle: { value: 0, easing: 'sineIn' } });
+        let sequence1 = cc.tween().sequence(rotate1, rotate2, rotate3, rotate4);
         cc.tween(node).then(sequence1).repeatForever().start();
         cc.tween(node).then(sequence1).repeatForever().start();
     }
     }
     /** 停止动画 */
     /** 停止动画 */

+ 3 - 3
mk_framework/assets/script/game/component/tween/UITween.ts

@@ -21,9 +21,9 @@ export class TweenData {
     @property({ displayName: "持续时间", tooltip: '单位:秒' }) public duration: number = 0.3;
     @property({ displayName: "持续时间", tooltip: '单位:秒' }) public duration: number = 0.3;
     @property({ displayName: "延迟时间", tooltip: '单位:秒' }) public delay: number = 0;
     @property({ displayName: "延迟时间", tooltip: '单位:秒' }) public delay: number = 0;
     @property({ displayName: "是否为差值" }) public isOffset: boolean = false;
     @property({ displayName: "是否为差值" }) public isOffset: boolean = false;
-    @property({ displayName: '完成回调', tooltip: "缓动动作完成时触发", type: cc.Component.EventHandler }) public onComplete: cc.Component.EventHandler = new cc.Component.EventHandler();
-    @property({ displayName: '开始回调', tooltip: "缓动动作启动时触发", type: cc.Component.EventHandler }) public onStart: cc.Component.EventHandler = new cc.Component.EventHandler();
-    @property({ displayName: '过程回调', tooltip: "缓动动作更新时触发", type: cc.Component.EventHandler }) public onUpdate: cc.Component.EventHandler = new cc.Component.EventHandler();
+    @property({ displayName: '完成回调', tooltip: "缓动完成时触发", type: cc.Component.EventHandler }) public onComplete: cc.Component.EventHandler = new cc.Component.EventHandler();
+    @property({ displayName: '开始回调', tooltip: "缓动启动时触发", type: cc.Component.EventHandler }) public onStart: cc.Component.EventHandler = new cc.Component.EventHandler();
+    @property({ displayName: '过程回调', tooltip: "缓动更新时触发", type: cc.Component.EventHandler }) public onUpdate: cc.Component.EventHandler = new cc.Component.EventHandler();
 }
 }
 /**
 /**
  * 缓动组件,目前只支持节点的三个基础属性
  * 缓动组件,目前只支持节点的三个基础属性

+ 91 - 0
mk_framework/assets/script/game/component/tween/ZPathFalling.ts

@@ -0,0 +1,91 @@
+
+const { ccclass, property, executeInEditMode, playOnFocus } = cc._decorator;
+
+/**
+ * @author 薛鸿潇
+ */
+@ccclass
+@executeInEditMode()
+@playOnFocus()
+export default class ZPathFalling extends cc.Component {
+    @property({ displayName: '自动播放' }) private play_on_load: boolean = true;
+    @property({ displayName: '完成回调', type: cc.Component.EventHandler }) public onComplete: cc.Component.EventHandler = new cc.Component.EventHandler();
+    /** 编辑器预览 */
+    private _edit_play: boolean = false;
+    @property({ displayName: '编辑器预览' })
+    get edit_play(): boolean {
+        if (this._edit_play && !this.edit_playing) {
+            this.edit_playing = true;
+            this.play();
+        }
+        return this._edit_play;
+    }
+    set edit_play(v: boolean) {
+        this._edit_play = v;
+        if (!v) this.stop();
+    }
+    /** 编辑器是否正在播放 */
+    private edit_playing = false;
+    onLoad() {
+
+    }
+
+    start() {
+        if (CC_EDITOR) {
+            this.edit_play && this.play();
+        } else {
+            this.play_on_load && this.play();
+        }
+    }
+
+    /** z字落地术 */
+    private play() {
+        // z字三点式
+        let end_pos1 = this.node.getPosition();
+        let end_pos2 = this.node.getPosition();
+        let end_pos3 = this.node.getPosition();
+        // 左右坐标
+        if (this.node.x >= 0) {
+            // 在右边,左飘
+            end_pos1.x -= this.node.width * 3;
+            end_pos2.x -= this.node.width * 1;
+            end_pos3.x -= this.node.width * 2;
+        } else {
+            // 在左边,右飘
+            end_pos1.x += this.node.width * 3;
+            end_pos2.x += this.node.width * 1;
+            end_pos3.x += this.node.width * 2;
+        }
+        // 下落
+        end_pos1.y -= this.node.height / 2;
+        end_pos2.y -= this.node.height;
+        end_pos3.y -= this.node.height * 1.2;
+        // // 上下坐标
+        // if (this.node.y <= -200) {
+        //     // 在下面
+        //     end_pos1.y += this.node.height / 1;
+        //     end_pos2.y += this.node.height * 1.5;
+        //     end_pos3.y += this.node.height * 2;
+        // } else {
+        //     // 在上面
+        //     end_pos1.y -= this.node.height / 2;
+        //     end_pos2.y -= this.node.height;
+        //     end_pos3.y -= this.node.height * 1.2;
+        // }
+        let pos1 = cc.tween().to(0.5, { position: end_pos1 }, { easing: 'cubicOut' })
+        let pos2 = cc.tween().to(0.5, { position: end_pos2 }, { easing: 'cubicOut' })
+        let pos3 = cc.tween().to(0.5, { position: end_pos3 }, { easing: 'cubicOut' })
+        let call1 = cc.tween().call(() => {
+            this.edit_playing = false;
+            this.edit_play = false;
+            this.onComplete.handler && this.onComplete.emit([this.node]);
+        })
+        cc.tween(this.node).then(pos1).then(pos2).then(pos3).then(call1).start();
+    }
+    /** 停止动画 */
+    private stop() {
+        this.edit_playing = false;
+        this.node.stopAllActions();
+    }
+    // update (dt) {}
+}

+ 9 - 0
mk_framework/assets/script/game/component/tween/ZPathFalling.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.8",
+  "uuid": "082f6b8d-56ea-406e-a0b4-164cf5fd3081",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}