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;
// }
// }
// }
}
联系客服