feat: 新增资源分包与启动场景,支持音效播放

This commit is contained in:
richarjiang
2025-09-28 08:54:00 +08:00
parent f27a27d2ce
commit e09c9a84cb
20 changed files with 1110 additions and 232 deletions

View File

@@ -1,4 +1,4 @@
import { _decorator, Component, Node, Vec3, input, Input, EventTouch, Camera, view, tween, Animation, Collider2D, Contact2DType, Label, Color, Canvas, UITransform } from 'cc';
import { _decorator, Component, Node, Vec3, input, Input, EventTouch, Camera, view, tween, Animation, Collider2D, Contact2DType, Label, Color, Canvas, UITransform, AudioSource } from 'cc';
import { TiledMapPathfinder } from './TiledMapPathfinder';
const { ccclass, property } = _decorator;
@@ -19,6 +19,9 @@ export class PlayerController extends Component {
@property(TiledMapPathfinder)
pathfinder: TiledMapPathfinder | null = null; // 寻路组件
@property(Node)
attackAudio: Node | null = null; // 攻击音效节点
@property({ range: [1, 300] })
moveSpeed: number = 300; // 移动速度(像素/秒)
@@ -400,6 +403,15 @@ export class PlayerController extends Component {
const monsterHp = parseInt(monsterLabel.string) || 0;
console.log('玩家生命值:', playerHp, '怪物生命值:', monsterHp);
// 播放攻击音效
if (this.attackAudio) {
const audioSource = this.attackAudio.getComponent(AudioSource);
if (audioSource) {
audioSource.play();
console.log('播放攻击音效');
}
}
// 播放攻击动画
const monsterAnimation = otherCollider.node.getComponent(Animation);
if (monsterAnimation) {
@@ -469,6 +481,15 @@ export class PlayerController extends Component {
}
this.isAttacking = false;
// 停止攻击音效
if (this.attackAudio) {
const audioSource = this.attackAudio.getComponent(AudioSource);
if (audioSource) {
audioSource.stop();
console.log('停止攻击音效');
}
}
}, 2);
}