Commit 35d3e306 authored by Tt's avatar Tt

点击碎裂

parent 3fd50703
This diff is collapsed.
...@@ -279,7 +279,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -279,7 +279,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
// 添加点击事件(如果节点上没有该事件) // 添加点击事件(如果节点上没有该事件)
pg.view.touchOn(candyNode, this.onTouchFireNode, this); pg.view.touchOn(candyNode, this.onTouchItemNode, this);
} }
/** /**
...@@ -334,17 +334,55 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -334,17 +334,55 @@ export default class SceneComponent extends MyCocosSceneComponent {
* @param e 事件对象或包含target属性的模拟事件对象 * @param e 事件对象或包含target属性的模拟事件对象
*/ */
private currentFireNode: CandyNode; private currentFireNode: CandyNode;
async onTouchFireNode(e) { async onTouchItemNode(e) {
const fireNode = e.target as CandyNode; if (this.touching) return;
this.touching = true;
pg.hw.playLocalAudio('fire_water'); const candyNode = e.target as CandyNode;
// 保存触摸数据 // 保存触摸数据
this.touchData = fireNode.data; this.touchData = candyNode.data;
this.touchData.parent = fireNode; this.touchData.parent = candyNode;
this.currentFireNode = fireNode; this.currentFireNode = candyNode;
// 获取糖果节点的位置和背景节点
const bgFullNode = candyNode.getChildByName('bg_full');
const bgBrokenNode = candyNode.getChildByName('bg_broken');
// 计算锤子移动到糖果右侧偏移量100,50的位置
const targetPos = candyNode.convertToWorldSpaceAR(cc.v2(160, -30));
const hammerWorldPos = this.btn_hammer.parent.convertToNodeSpaceAR(targetPos);
// 保存锤子原始位置和旋转角度
const originalPos = cc.v2(this.btn_hammer.x, this.btn_hammer.y);
const originalRotation = this.btn_hammer.angle;
// 保存当前滚动状态,并暂停滚动
const originalScrollState = this.needScroll;
this.needScroll = false;
// 移除了消防车喷水动画相关代码 // 播放锤子移动到目标位置的动画
await pg.time.delay(1); cc.tween(this.btn_hammer)
.to(0.2, { x: hammerWorldPos.x, y: hammerWorldPos.y })
.call(() => {
// 播放锤子旋转敲击的动画
cc.tween(this.btn_hammer)
.to(0.15, { angle: -45 }) // 锤子向上旋转准备敲击
.to(0.15, { angle: 30 }) // 锤子向下旋转敲击
.call(() => {
pg.view.visible(bgFullNode, false);
pg.view.visible(bgBrokenNode, true);
})
.delay(0.3) // 等待0.3秒
.to(0.2, { x: originalPos.x, y: originalPos.y, angle: originalRotation }) // 锤子回到原位
.call(() => {
// 恢复原来的滚动状态
this.needScroll = originalScrollState;
})
.start();
})
.start();
// 等待动画完成后显示卡片
await pg.time.delay(1.1);
this.showCard(true, 'init'); this.showCard(true, 'init');
} }
...@@ -375,7 +413,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -375,7 +413,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
} else { } else {
// 如果需要滚动,标记节点为已点击但保持显示状态 // 如果需要滚动,标记节点为已点击但保持显示状态
// 将节点设置为不可交互,防止重复点击 // 将节点设置为不可交互,防止重复点击
fireNode.off(cc.Node.EventType.TOUCH_END, this.onTouchFireNode, this); fireNode.off(cc.Node.EventType.TOUCH_END, this.onTouchItemNode, this);
} }
// 移除了与页面a和页面b相关的逻辑 // 移除了与页面a和页面b相关的逻辑
...@@ -744,7 +782,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -744,7 +782,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
// 处理糖果区域滚动 // 处理糖果区域滚动
if (this.needScroll && this.layout && this.layout.childrenCount > 0) { if (this.needScroll && !this.touching && this.layout && this.layout.childrenCount > 0) {
// 移动糖果区域 // 移动糖果区域
this.layout.x -= this.scrollSpeed * dt; this.layout.x -= this.scrollSpeed * dt;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment