This commit is contained in:
computer\尼卡 2025-08-06 19:29:20 +08:00
parent b52fdb1385
commit 1b267ebc8e
4 changed files with 320 additions and 53 deletions

View File

@ -153,6 +153,7 @@ export default class Block extends cc.Component {
//计时器
private scheduleCallback: any = null;
private scheduleCallback2: any = null;
private scheduleCallback3: any = null;
isEliminatedByHammer: boolean = false; // 标记是否被锤子消除过
onLoad() {
@ -747,58 +748,14 @@ export default class Block extends cc.Component {
eliminate() {
clearTimeout(this.scheduleCallback2);
clearTimeout(this.scheduleCallback);
clearTimeout(this.scheduleCallback3);
let self = this;
//锤子状态消失
MapConroler._instance.pause = true;
if (MapConroler._instance.ismagic) {
this.scheduleCallback = setTimeout(() => {
// 记录添加magic时的锚点
this.node.anchorX = 0.5;
this.node.anchorY = 0.5;
this.node.addChild(new cc.Node("magic"));
let effectNode = this.node.getChildByName("magic");
effectNode.setPosition(0, 0);
// 改锚点后修正magic的位置
this.node.anchorX = 1;
this.node.anchorY = 0;
// 重新设置magic的位置使其视觉上不变
let parentSize = this.node.getContentSize();
effectNode.setPosition(
effectNode.x + parentSize.width * (0.5 - 1),
effectNode.y + parentSize.height * (0.5 - 0)
);
switch (this.node.name) {
case "block14":
this.node.anchorX = 0.66;
this.node.anchorY = 0;
effectNode.setPosition(-50, 120);
break;
case "block18":
this.node.anchorX = 0.66;
this.node.anchorY = 0;
effectNode.setPosition(-50, 200);
break;
case "block10":
effectNode.setPosition(0, 200);
break;
case "block21":
effectNode.setPosition(0, 130);
break;
case "block16":
effectNode.setPosition(0, 180);
break;
default:
break;
}
effectNode.zIndex = 1000;
effectNode.addComponent(sp.Skeleton);
effectNode.getComponent(sp.Skeleton).skeletonData = this.magic_SkeletonData;
effectNode.getComponent(sp.Skeleton).setAnimation(0, "play", false);
this.createLabelsForBlocksWithCustomDelay(0.2)
if (this.type == BlockType.) {
this.node.getChildByName("freeze").getComponent("Freeze").reduce(2);
MapConroler._instance.ismagic = false;
@ -829,10 +786,14 @@ export default class Block extends cc.Component {
this.node.getChildByName("boom").getComponent("Boom").stopBoom();
}
this.scheduleCallback2 = setTimeout(() => {
//如果方块可以消除
MapConroler._instance.blockNum -= 1;
MapConroler._instance.special_Treatment(this.node);
}, 950);
this.scheduleCallback2 = setTimeout(() => {
//如果方块可以消除
// MapConroler._instance.blockNum -= 1;
// MapConroler._instance.special_Treatment(this.node);
var self = this;
this.removeMapBlock();
MapConroler._instance.judgeWin(1);
@ -860,10 +821,10 @@ export default class Block extends cc.Component {
MapConroler._instance.failLevel("lock");
}
}
}, 500);
}, 900);
MapConroler._instance.ismagic = false;
}, 950);
}, 1350);
}
@ -1598,6 +1559,271 @@ export default class Block extends cc.Component {
this.node.y = this.node.y - distance;
}
}
createSingleBlockEffect(blockPos: any, index: number, blockSize: number, baseOffset: cc.Vec2) {
const effectNode = new cc.Node(`magic_effect_${index}`);
const skeletonComponent = effectNode.addComponent(sp.Skeleton);
if (!this.magic_SkeletonData) {
console.error("magic_SkeletonData 资源未加载或为空");
return;
}
skeletonComponent.skeletonData = this.magic_SkeletonData;
skeletonComponent.premultipliedAlpha = false;
let actualX = blockPos.x * blockSize + baseOffset.x;
let actualY = blockPos.y * blockSize + baseOffset.y;
effectNode.setAnchorPoint(0.5, 0.5);
// 计算在世界坐标系中的位置
const worldPos = this.node.convertToWorldSpaceAR(cc.v2(actualX - 65, actualY + 70));
// 获取 Canvas 节点
const canvas = cc.find('Canvas');
if (!canvas) {
console.error("找不到 Canvas 节点");
return;
}
// 将世界坐标转换为 Canvas 的本地坐标
const canvasPos = canvas.convertToNodeSpaceAR(worldPos);
effectNode.setPosition(canvasPos);
// 设置最高层级,确保在所有其他节点之上
effectNode.zIndex = 9999;
// 添加到 Canvas 节点下
canvas.addChild(effectNode);
this.playMagicAnimation(skeletonComponent, index);
// 可选:添加自动清理机制
this.scheduleOnce(() => {
if (effectNode && effectNode.isValid) {
effectNode.removeFromParent();
effectNode.destroy();
}
}, 3); // 3秒后自动清理
}
// 播放魔法动画的辅助方法
playMagicAnimation(skeletonComponent: sp.Skeleton, index: number) {
try {
// 检查动画是否存在
if (!skeletonComponent.findAnimation("play")) {
console.error(`动画 "play" 不存在于 Spine 资源中`);
return;
}
skeletonComponent.setAnimation(0, "play", false);
//播放完自动清理
// 监听动画完成事件
skeletonComponent.setCompleteListener((trackEntry, loopCount) => {
// 动画播放完成后自动清理节点
if (skeletonComponent.node && skeletonComponent.node.isValid) {
console.log(`${index} 个特效动画播放完成,开始清理节点`);
// 移除节点并销毁
skeletonComponent.node.removeFromParent();
skeletonComponent.node.destroy();
}
});
} catch (error) {
console.error(`播放第 ${index} 个方块动画时出错:`, error);
}
}
// 清理
clearPreviousEffects() {
const children = this.node.children;
for (let i = children.length - 1; i >= 0; i--) {
const child = children[i];
if (child.name.startsWith('magic_effect_')) {
child.removeFromParent();
child.destroy();
}
}
}
createLabelsForBlocksWithCustomDelay(delayBetweenBlocks: number = 0.1) {
if (!this.allBlocks || this.allBlocks.length === 0) {
console.warn("allBlocks 数组为空或未定义");
return;
}
const blockSize = 120;
const baseOffset = cc.v2(0, 0);
this.clearPreviousEffects();
let createOrder = [
[0],
];
switch (this.node.name) {
case "block0":
createOrder = [
[0]
];
break;
case "block1":
createOrder = [
[1],
[0]
];
break;
case "block2":
createOrder = [
[1],
[0]
];
break;
case "block3":
createOrder = [
[1],
[0, 2],
];
break;
case "block4":
createOrder = [
[1],
[0, 2]
];
break;
case "block5":
createOrder = [
[0],
[1, 3],
[2]
];
break;
case "block6":
createOrder = [
[2],
[1, 3],
[0]
];
break;
case "block7":
createOrder = [
[2],
[1, 3],
[0]
];
break;
case "block8":
createOrder = [
[1],
[0, 2],
[3]
];
break;
case "block9":
createOrder = [
[0],
[1, 3],
[2]
];
break;
case "block10":
createOrder = [
[3],
[1, 2],
[0]
];
break;
case "block11":
createOrder = [
[3],
[0, 2],
[1]
];
break;
case "block12":
createOrder = [
[0],
[1, 3],
[2]
];
break;
case "block13":
createOrder = [
[2],
[1, 3],
[0]
];
break;
case "block14":
createOrder = [
[1],
[0, 2, 3],
];
break;
case "block15":
createOrder = [
[1],
[0, 2, 3],
];
break;
case "block16":
createOrder = [
[2],
[0, 1, 3],
];
break;
case "block17":
createOrder = [
[1],
[0, 2, 3],
];
break;
case "block18":
createOrder = [
[1],
[0, 2, 3, 4],
];
break;
case "block19":
createOrder = [
[0],
[1, 2],
];
break;
case "block20":
createOrder = [
[1],
[2, 0],
];
break;
case "block21":
createOrder = [
[1],
[2, 0],
];
break;
case "block22":
createOrder = [
[1],
[2, 0],
];
break;
}
let currentDelay = 0;
createOrder.forEach((batch, batchIndex) => {
batch.forEach(blockIndex => {
if (blockIndex < this.allBlocks.length) {
const blockPos = this.allBlocks[blockIndex];
this.scheduleOnce(() => {
this.createSingleBlockEffect(blockPos, blockIndex, blockSize, baseOffset);
}, currentDelay);
}
});
currentDelay += delayBetweenBlocks;
});
}
}

View File

@ -63,6 +63,7 @@ export default class JiaZai extends cc.Component {
@property(cc.Node)
setUi: cc.Node = null;
scheduleCallback2: any;
private isFirstLaunch: boolean = true; // 添加首次启动标志
// //月卡
// @property(cc.Node)
// monthCardBtn: cc.Node = null;
@ -172,7 +173,46 @@ export default class JiaZai extends cc.Component {
//console.log("音乐开关", cc.fx.GameConfig.GM_INFO.musicOpen);
AudioManager._instance.playMusicGame();
// this.openMonthCard();
if (typeof wx !== 'undefined') {
wx.onShow(() => {
// 只有非首次启动时才调用 onGameShow
if (!this.isFirstLaunch) {
this.onGameShow();
}
// 标记首次启动已完成
});
wx.onHide(() => {
this.onGameHide();
this.isFirstLaunch = false;
});
}
}
onGameHide() {
console.log("执行onGameHide", cc.fx.GameConfig.GM_INFO.min_Time);
this.stopHeathTimeCutDown();
this.stopTimeCutDown();
this.stopPowerTime();
}
onGameShow() {
cc.fx.GameTool.getHealth((data) => {
NumberToImage.numberToImageNodes((cc.fx.GameConfig.GM_INFO.level + 1), 43, 15, "level_", this.level, true);
NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.coin, 30, 15, "coin_", this.coin, true);
this.setHealthInfo(true);
});
console.log("执行on", cc.fx.GameConfig.GM_INFO.min_Time);
if (this.node.getChildByName("heathpop") && this.node.getChildByName("heathpop").active == true) {
const heathComponent = this.node.getChildByName("heathpop").getComponent("heathnum");
if (heathComponent && heathComponent.timeNode &&
cc.fx.GameConfig.GM_INFO.hp < cc.fx.GameConfig.GM_INFO.hp_Max) {
this.startHeathTimeCutDown(heathComponent.timeNode);
}
}
}
start() {
@ -232,6 +272,7 @@ export default class JiaZai extends cc.Component {
let heathPop = health.getComponent("heathnum").heatht;
heathPop.scale = 0.7;
this.heath = heathPop; // 保存heath预制体引用
console.log("Health:", this.node.children)
let swichs = health.getComponent("heathnum").switchNode;
let timeNode = health.getComponent("heathnum").timeNode;
let switchButtons = health.getComponent("heathnum").switchButtons;
@ -753,7 +794,6 @@ export default class JiaZai extends cc.Component {
closeLoad() {
this.node.getChildByName("Loading").active = false;
}
updatePower() {
if (cc.fx.GameConfig.GM_INFO.userPowerTime != 0) {
let nowTime = Math.floor(Date.now() / 1000);

View File

@ -1778,8 +1778,9 @@ export default class MapConroler extends cc.Component {
if (data.type == "time") {
this.timeNumber = 21;
this.add_Time += 20;
NumberToImage.getTimeMargin(20, 50, "time_", this.timeLabel)
}
// NumberToImage.getTimeMargin(20, 50, "time_", this.timeLabel)
this.blockNum = this.blocks.length;
if (this.blockNum == 0) this.nextLevel();

View File

@ -824,7 +824,7 @@
"_contentSize": {
"__type__": "cc.Size",
"width": 1080,
"height": 1700
"height": 1900
},
"_anchorPoint": {
"__type__": "cc.Vec2",