大,第1张

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;

    //         }

    //     }

    // }


}


本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
白度搜_经验知识百科全书 »

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情