薛鸿潇 5 лет назад
Родитель
Сommit
064855188e

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

@@ -0,0 +1,60 @@
+
+const { ccclass, property } = cc._decorator;
+/** 闪烁可选类型 */
+enum StateType {
+    /** 出去 */
+    out = 0,
+    /** 移动中 */
+    moving = 1,
+    /** 回来 */
+    back = 2,
+};
+/**
+ * 点击弹出或返回
+ * - 节点需要添加按钮组件
+ * - 组件会记录移动前的位置,点击后移动配置好的距离,再次点击则返回。
+ * - 移动中点击无效
+ * @author 薛鸿潇
+ */
+@ccclass
+export default class ClickMoveBy extends cc.Component {
+    /** 移动的距离 */
+    @property({ tooltip: '要移动的距离' })
+    vec_move: cc.Vec2 = cc.Vec2.ZERO;
+    /** 当前状态 */
+    state: number = StateType.out;
+    /** 是否要返回 */
+    is_back: boolean = false;
+    onLoad() {
+        this.node.on('click', this.StartMoveBy, this)
+    }
+
+    start() {
+        if (!this.node.getComponent(cc.Button)) this.node.addComponent(cc.Button);
+    }
+    /**
+     * 开始移动
+     * - 移动指定距离 || 返回相反的距离
+     * @returns 
+     */
+    StartMoveBy() {
+        if (this.state === StateType.moving) return;
+        let next_state = 0
+        let temp_vec_move = cc.Vec2.ZERO
+        if (this.state === StateType.out) {
+            temp_vec_move = this.vec_move
+            next_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
+        }
+        this.state = StateType.moving
+        let move1 = cc.tween().by(0.5, { position: { value: temp_vec_move, easing: 'backOut' } })
+        let call1 = cc.tween().call(() => {
+            this.state = next_state
+        })
+        cc.tween(this.node).then(move1).then(call1).start();
+    }
+    // update (dt) {}
+}

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

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.8",
+  "uuid": "b4358c91-0f5d-4b3c-b36d-0dbb19d93b0a",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}