打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
userphoto

2023.03.30 江苏

关注

const { ccclass, property } = cc._decorator;


@ccclass

export default class MainScene extends cc.Component {


    // @property

    // CARD_WIDTH: number = 300;

    // @property

    // CARD_HEIGHT: number = 400;

    // @property

    // CARD_GAP: number = 1;

    private cardNum: number = 13; // 牌的数量

    private cardSize: cc.Size = cc.size(300, 400); // 牌的尺寸

    private cardSpace: number = 10; // 牌的间隔

    private midIndex: number = 5; // 中间牌的下标,数组下标从0开始

    private CENTER_X: number = 0;

    private CENTER_Y: number = 0;


    private ok: boolean = false;

    private canMove = true;

    start() {

        for (let i = 0; i < this.node.childrenCount; i++) {

            //const x: number = -100;

            const y: number = (i - this.midIndex) * 400;

            this.node.children[i].setContentSize(this.cardSize);

            this.node.children[i].setPosition(10, y);

        }

        this.node.on(cc.Node.EventType.TOUCH_MOVE, this.move, this)

    }

    move(event: cc.Event.EventTouch): void {

        if (!this.canMove) return; // 如果无法移动,则退出函数

        this.canMove = false; // 设置为不可移动

        const touchDelta = event.getDelta();

        if (touchDelta.y > 0) {

            for (let i = 0; i < this.node.childrenCount; i++) {

                this.node.children[i].y -=400;

            }

        }

        // 在合适的时机将标记设置为 true,可以使用定时器或回调函数实现

        setTimeout(() => {

            this.canMove = true;

        }, 1000); // 这里设置为 1 秒后可移动

    }


    // protected update(dt: number): void {

    //     if (this.ok) {

    //         for (let i = 0; i < this.node.childrenCount; i++) {

    //             this.node.children[i].y -=50*dt;

    //         }

    //     }

    // }


}

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
Private Number
基于d3.js的组织结构图实现
递归遍历各种数据结构,深入理解前序遍历,后续遍历,深度优先dfs。
VBA常用代码解析(第三十八讲)
一个简单的多叉树C++实现
成功el-tree获取复选框选中节点
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服