做电商网站价钱,红酒网页设计图片,网站评测的作用,企业网站设计素材首先设定一下 单个 方块 cell 类#xff1a;
类定义和属性 init 方法 用于初始化方块#xff0c;接收游戏实例、数据、宽度、道具类型和位置。 onWarning 方法 设置警告精灵的帧#xff0c;并播放闪烁动作#xff0c;用于显示方块的警告状态。 grow 方法 根据传入的方向…
首先设定一下 单个 方块 cell 类
类定义和属性 init 方法 用于初始化方块接收游戏实例、数据、宽度、道具类型和位置。 onWarning 方法 设置警告精灵的帧并播放闪烁动作用于显示方块的警告状态。 grow 方法 根据传入的方向上下左右调整方块的大小实现方块的增长效果。 - bindEvent 方法绑定触摸事件到方块节点。 - onTouched 方法处理触摸事件包括用户点击和被其他方块触发的情况。根据方块状态和游戏状态执行相应的逻辑。 onBlockPop 方法 在方块被消除时调用处理连锁反应和道具触发的逻辑。 playFallAction 方法 控制方块下降的动画更新方块的位置。 - playStartAction 控制方块生成时的动画。 - playDieAction 控制方块消失时的动画并返回一个 Promise以便在动画完成后执行其他操作。 - surfaceAction 控制方块浮出水面的动画。 - generatePropAction 可能是用于生成道具的动画但具体实现为空。
init 方法是这段脚本中用于初始化方块实例的关键方法
init(g, data, width, itemType, pos) {this._game g; // 游戏实例this._status 1; // 初始化方块状态为可触发点击if (pos) {// 如果提供了位置参数则使用}pos pos || {x: data.x,y: data.y};this._itemType itemType || 0; // 初始化道具类型this.warningType 0; // 初始化警告类型this.isPush false; // 初始化是否被推动this.bindEvent(); // 绑定事件this.color data.color || Math.ceil(Math.random() * 4); // 初始化方块颜色this.colorSprite this.node.getChildByName(color).getComponent(cc.Sprite);// 设置方块颜色精灵的帧this.colorSprite.spriteFrame itemType ? g.propSpriteFrame[(itemType - 1) * 4 this.color - 1] : this._game.blockSprite[this.color - 1];this.warningSprite.spriteFrame ; // 初始化警告精灵的帧为空this._width width; // 保存方块宽度this._controller g._controller; // 获取控制器this.lightSprite.node.active false; // 初始时关闭光效精灵// 计算方块宽度this.node.width this.node.height width;this.startTime data.startTime; // 初始化开始时间this.iid data.y; // 初始化方块在网格中的行索引this.jid data.x; // 初始化方块在网格中的列索引this.node.x -(730 / 2 - g.gap - width / 2) pos.x * (width g.gap);this.node.y (730 / 2 - g.gap - width / 2) - pos.y * (width g.gap);this.node.rotation 0; // 初始化方块旋转角度为0this.playStartAction(); // 播放开始动画
},
grow 方法是方块在游戏中进行变形或增长时的关键逻辑它使得方块能够根据游戏规则在特定方向上扩展
grow(type) { //1234 代表上、下、左、右switch (type) {case 1:// 如果方块不是在水平增长状态并且可以向上增长if (this.growType ! 2) {this.colorSprite.node.height this._game.gap * 2this.colorSprite.node.y this._game.gapthis.growType 1}breakcase 2:// 如果方块不是在水平增长状态并且可以向下增长if (this.growType ! 2) {this.colorSprite.node.height this._game.gap * 2this.colorSprite.node.y - this._game.gapthis.growType 1}breakcase 3:// 如果方块不是在垂直增长状态并且可以向左增长if (this.growType ! 1) {this.colorSprite.node.width this._game.gap * 2this.colorSprite.node.x - this._game.gapthis.growType 2}breakcase 4:// 如果方块不是在垂直增长状态并且可以向右增长if (this.growType ! 1) {this.colorSprite.node.width this._game.gap * 2this.colorSprite.node.x this._game.gapthis.growType 2}break}
}, 详细介绍可以链接
微信小游戏之三消一 (qq.com)https://mp.weixin.qq.com/s/SUPaWJ8bm5wrtLPZLiktjQ?token1657907189langzh_CN