From d089699c3695538395a94952360db6b610b7f0c3 Mon Sep 17 00:00:00 2001 From: walkpan Date: Mon, 3 Nov 2025 13:10:43 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=8B=B1=E9=9B=84):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E8=8B=B1=E9=9B=84=E7=A7=BB=E5=8A=A8=E5=92=8C=E7=A2=B0=E6=92=9E?= =?UTF-8?q?=E9=80=BB=E8=BE=91=20fix=E7=94=B1=E4=BA=8E=20setScale=20?= =?UTF-8?q?=E4=BC=9A=E5=BD=B1=E5=93=8D=E7=89=A9=E7=90=86=E5=88=A4=E6=96=AD?= =?UTF-8?q?,=E9=80=A0=E6=88=90=E7=8E=A9=E5=AE=B6=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E5=A4=9A=E6=AC=A1=E8=A2=AB=E6=94=BB=E5=87=BB=E8=A7=A6=E5=8F=91?= =?UTF-8?q?=E5=9B=9E=E8=B0=83=20-=20=E6=B7=BB=E5=8A=A0=E8=8B=B1=E9=9B=84?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E6=96=B9=E5=90=91=E7=BC=93=E5=AD=98=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E9=A2=91=E7=B9=81=E8=BD=AC=E5=90=91=20-=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E8=8B=B1=E9=9B=84=E7=A2=B0=E6=92=9E=E5=99=A8=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E7=8A=B6=E6=80=81=E7=AE=A1=E7=90=86=20-=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E8=8B=B1=E9=9B=84=E5=90=8E=E9=80=80=E5=8A=A8=E7=94=BB?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E8=A7=A6=E5=8F=91=E9=97=AE=E9=A2=98=20-=20?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=83=A8=E5=88=86=E8=8B=B1=E9=9B=84prefab?= =?UTF-8?q?=E7=9A=84=E7=A2=B0=E6=92=9E=E7=BB=84=E5=92=8C=E4=BC=A0=E6=84=9F?= =?UTF-8?q?=E5=99=A8=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/resources/game/heros/ha1.prefab | 2 +- assets/resources/game/heros/hc1.prefab | 2 +- assets/resources/game/heros/hh1.prefab | 2 +- assets/resources/game/heros/hk1.prefab | 6 +-- assets/resources/game/heros/hm1.prefab | 2 +- assets/resources/game/heros/hm2.prefab | 6 +-- assets/resources/game/heros/hz1.prefab | 2 +- assets/resources/game/heros/mo1.prefab | 4 +- assets/resources/game/heros/mo2.prefab | 4 +- assets/resources/game/heros/mo3.prefab | 2 +- assets/resources/game/heros/mo4.prefab | 4 +- .../game/skill/atk/b_arrow_blue.prefab | 2 +- assets/resources/game/skill/ready.meta | 9 +++++ assets/script/game/hero/Hero.ts | 4 +- assets/script/game/hero/HeroMove.ts | 40 ++++++++++++------- assets/script/game/hero/HeroViewComp.ts | 14 ++++++- 16 files changed, 70 insertions(+), 35 deletions(-) create mode 100644 assets/resources/game/skill/ready.meta diff --git a/assets/resources/game/heros/ha1.prefab b/assets/resources/game/heros/ha1.prefab index 51401d0a..a8f90e70 100644 --- a/assets/resources/game/heros/ha1.prefab +++ b/assets/resources/game/heros/ha1.prefab @@ -991,7 +991,7 @@ "node": { "__id__": 1 }, - "_enabled": false, + "_enabled": true, "__prefab": { "__id__": 62 }, diff --git a/assets/resources/game/heros/hc1.prefab b/assets/resources/game/heros/hc1.prefab index 0cd1ec6a..9e93c55c 100644 --- a/assets/resources/game/heros/hc1.prefab +++ b/assets/resources/game/heros/hc1.prefab @@ -991,7 +991,7 @@ "node": { "__id__": 1 }, - "_enabled": false, + "_enabled": true, "__prefab": { "__id__": 62 }, diff --git a/assets/resources/game/heros/hh1.prefab b/assets/resources/game/heros/hh1.prefab index 3f97e9b5..5ed5624e 100644 --- a/assets/resources/game/heros/hh1.prefab +++ b/assets/resources/game/heros/hh1.prefab @@ -991,7 +991,7 @@ "node": { "__id__": 1 }, - "_enabled": false, + "_enabled": true, "__prefab": { "__id__": 62 }, diff --git a/assets/resources/game/heros/hk1.prefab b/assets/resources/game/heros/hk1.prefab index 5e68027c..65259bf1 100644 --- a/assets/resources/game/heros/hk1.prefab +++ b/assets/resources/game/heros/hk1.prefab @@ -961,7 +961,7 @@ "__prefab": { "__id__": 60 }, - "enabledContactListener": true, + "enabledContactListener": false, "bullet": false, "awakeOnLoad": true, "_group": 4, @@ -991,7 +991,7 @@ "node": { "__id__": 1 }, - "_enabled": false, + "_enabled": true, "__prefab": { "__id__": 62 }, @@ -1009,7 +1009,7 @@ "_size": { "__type__": "cc.Size", "width": 49.3, - "height": 72.9 + "height": 60.9 }, "_id": "" }, diff --git a/assets/resources/game/heros/hm1.prefab b/assets/resources/game/heros/hm1.prefab index 84c71aa5..3866b471 100644 --- a/assets/resources/game/heros/hm1.prefab +++ b/assets/resources/game/heros/hm1.prefab @@ -991,7 +991,7 @@ "node": { "__id__": 1 }, - "_enabled": false, + "_enabled": true, "__prefab": { "__id__": 62 }, diff --git a/assets/resources/game/heros/hm2.prefab b/assets/resources/game/heros/hm2.prefab index ae071853..9205e379 100644 --- a/assets/resources/game/heros/hm2.prefab +++ b/assets/resources/game/heros/hm2.prefab @@ -896,8 +896,8 @@ }, "_contentSize": { "__type__": "cc.Size", - "width": 80, - "height": 8 + "width": 60, + "height": 80 }, "_anchorPoint": { "__type__": "cc.Vec2", @@ -991,7 +991,7 @@ "node": { "__id__": 1 }, - "_enabled": false, + "_enabled": true, "__prefab": { "__id__": 62 }, diff --git a/assets/resources/game/heros/hz1.prefab b/assets/resources/game/heros/hz1.prefab index 5a25e30a..3efc8c44 100644 --- a/assets/resources/game/heros/hz1.prefab +++ b/assets/resources/game/heros/hz1.prefab @@ -991,7 +991,7 @@ "node": { "__id__": 1 }, - "_enabled": false, + "_enabled": true, "__prefab": { "__id__": 62 }, diff --git a/assets/resources/game/heros/mo1.prefab b/assets/resources/game/heros/mo1.prefab index b7f85290..aa2549d1 100644 --- a/assets/resources/game/heros/mo1.prefab +++ b/assets/resources/game/heros/mo1.prefab @@ -988,12 +988,12 @@ "node": { "__id__": 1 }, - "_enabled": false, + "_enabled": true, "__prefab": { "__id__": 62 }, "tag": 0, - "_group": 4, + "_group": 2, "_density": 1, "_sensor": true, "_friction": 0.2, diff --git a/assets/resources/game/heros/mo2.prefab b/assets/resources/game/heros/mo2.prefab index 225e00f5..55c2a3e2 100644 --- a/assets/resources/game/heros/mo2.prefab +++ b/assets/resources/game/heros/mo2.prefab @@ -991,12 +991,12 @@ "node": { "__id__": 1 }, - "_enabled": false, + "_enabled": true, "__prefab": { "__id__": 62 }, "tag": 0, - "_group": 4, + "_group": 2, "_density": 1, "_sensor": true, "_friction": 0.2, diff --git a/assets/resources/game/heros/mo3.prefab b/assets/resources/game/heros/mo3.prefab index 5930ffc1..6327aed3 100644 --- a/assets/resources/game/heros/mo3.prefab +++ b/assets/resources/game/heros/mo3.prefab @@ -991,7 +991,7 @@ "node": { "__id__": 1 }, - "_enabled": false, + "_enabled": true, "__prefab": { "__id__": 62 }, diff --git a/assets/resources/game/heros/mo4.prefab b/assets/resources/game/heros/mo4.prefab index 849d8af8..de496613 100644 --- a/assets/resources/game/heros/mo4.prefab +++ b/assets/resources/game/heros/mo4.prefab @@ -991,14 +991,14 @@ "node": { "__id__": 1 }, - "_enabled": false, + "_enabled": true, "__prefab": { "__id__": 62 }, "tag": 0, "_group": 2, "_density": 1, - "_sensor": false, + "_sensor": true, "_friction": 0.2, "_restitution": 0, "_offset": { diff --git a/assets/resources/game/skill/atk/b_arrow_blue.prefab b/assets/resources/game/skill/atk/b_arrow_blue.prefab index a6850817..229854bf 100644 --- a/assets/resources/game/skill/atk/b_arrow_blue.prefab +++ b/assets/resources/game/skill/atk/b_arrow_blue.prefab @@ -513,7 +513,7 @@ "tag": 0, "_group": 1, "_density": 1, - "_sensor": false, + "_sensor": true, "_friction": 0.2, "_restitution": 0, "_offset": { diff --git a/assets/resources/game/skill/ready.meta b/assets/resources/game/skill/ready.meta new file mode 100644 index 00000000..06058c72 --- /dev/null +++ b/assets/resources/game/skill/ready.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.2.0", + "importer": "directory", + "imported": true, + "uuid": "e44e387b-e119-4ea3-8c61-90be55888ce5", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/script/game/hero/Hero.ts b/assets/script/game/hero/Hero.ts index 7f1889ef..b227adf6 100644 --- a/assets/script/game/hero/Hero.ts +++ b/assets/script/game/hero/Hero.ts @@ -1,4 +1,4 @@ -import { instantiate, Node, Prefab, Vec3 ,v3,resources,SpriteFrame,Sprite,SpriteAtlas} from "cc"; +import { instantiate, Node, Prefab, Vec3 ,v3,resources,SpriteFrame,Sprite,SpriteAtlas, BoxCollider2D} from "cc"; import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { smc } from "../common/SingletonModuleComp"; @@ -47,6 +47,8 @@ export class Hero extends ecs.Entity { var node = instantiate(prefab); var scene = smc.map.MapView.scene; node.parent = scene.entityLayer!.node! + const collider = node.getComponent(BoxCollider2D); + if (collider) collider.enabled = false; // 先禁用 node.setPosition(pos) // console.log("hero load",pos) var hv = node.getComponent(HeroViewComp)!; diff --git a/assets/script/game/hero/HeroMove.ts b/assets/script/game/hero/HeroMove.ts index 814619da..9a071588 100644 --- a/assets/script/game/hero/HeroMove.ts +++ b/assets/script/game/hero/HeroMove.ts @@ -15,11 +15,14 @@ export class HeroMoveComp extends ecs.Comp { targetX: number = 0; /** 是否处于移动状态 */ moving: boolean = true; + /** 当前朝向缓存:避免频繁setScale */ + currentFacing: number = 1; reset() { this.direction = 1; this.targetX = 0; this.moving = true; + this.currentFacing = 1; } } @@ -73,12 +76,10 @@ export class HeroMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpd // 根据敌人位置调整移动方向和朝向 if (enemyX > currentX) { move.direction = 1; // 向右移动 - view.node.setScale(1, 1, 1); // 面向右侧 - view.node.getChildByName("top").setScale(1, 1, 1); // 面向右侧 + this.setFacing(view, move, 1); // 🔥 使用优化的转向方法 } else { move.direction = -1; // 向左移动 - view.node.setScale(-1, 1, 1); // 面向左侧 - view.node.getChildByName("top").setScale(-1, 1, 1); // 面向左侧 + this.setFacing(view, move, -1); // 🔥 使用优化的转向方法 } // 继续向敌人方向移动 @@ -112,14 +113,8 @@ export class HeroMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpd const delta = (model.Attrs[Attrs.SPEED]/3) * this.dt * direction; const newX = view.node.position.x + delta; - // 设置朝向 - if (direction === 1) { - view.node.setScale(1, 1, 1); // 面向右侧 - view.node.getChildByName("top").setScale(1, 1, 1); // 面向右侧 - } else { - view.node.setScale(-1, 1, 1); // 面向左侧 - view.node.getChildByName("top").setScale(-1, 1, 1); // 面向左侧 - } + // 🔥 使用优化的转向方法 + this.setFacing(view, move, direction); // 确保不会超过目标位置 if (direction === 1 && newX > finalTargetX) { @@ -134,8 +129,7 @@ export class HeroMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpd view.status_change("idle"); // 到达目标位置后,面向右侧(敌人方向) move.direction = 1; - view.node.setScale(1, 1, 1); // 面向右侧 - view.node.getChildByName("top").setScale(1, 1, 1); // 面向右侧 + this.setFacing(view, move, 1); // 🔥 使用优化的转向方法 } } else { view.status_change("idle"); @@ -143,6 +137,24 @@ export class HeroMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpd } } + /** + * 🔥 优化的转向方法:只在真正需要改变朝向时才调用setScale + * 避免频繁的setScale调用导致碰撞器重新计算 + */ + private setFacing(view: HeroViewComp, move: HeroMoveComp, newFacing: number) { + // 只有当朝向真正改变时才更新 + if (move.currentFacing !== newFacing) { + move.currentFacing = newFacing; + view.node.setScale(newFacing, 1, 1); + + // 安全获取top节点 + const topNode = view.node.getChildByName("top"); + if (topNode) { + topNode.setScale(newFacing, 1, 1); + } + } + } + /** 检查是否存在敌人 */ private checkEnemiesExist(entity: ecs.Entity): boolean { const team = entity.get(HeroAttrsComp).fac; diff --git a/assets/script/game/hero/HeroViewComp.ts b/assets/script/game/hero/HeroViewComp.ts index c9afc700..bdd91df4 100644 --- a/assets/script/game/hero/HeroViewComp.ts +++ b/assets/script/game/hero/HeroViewComp.ts @@ -311,12 +311,24 @@ export class HeroViewComp extends CCComp { this.back() this.showDamage(damage, isCrit, SConf.DAnm); // 暴击状态由战斗系统内部处理, DAnm和EAnm共用设定数组 } + + private isBackingUp: boolean = false; // 🔥 添加后退状态标记 + //后退 back(){ + // 🔥 防止重复调用后退动画 + if (this.isBackingUp) return; + if(this.model.fac==FacSet.MON) { + this.isBackingUp = true; // 🔥 设置后退状态 let tx=this.node.position.x+30 if(tx > 320) tx=320 - tween(this.node).to(0.1, { position:v3(tx,this.node.position.y,0)}).start() + tween(this.node) + .to(0.1, { position:v3(tx,this.node.position.y,0)}) + .call(() => { + this.isBackingUp = false; // 🔥 动画完成后重置状态 + }) + .start() } //英雄不再后退 // if(this.model.fac==FacSet.HERO) {