完成动画组件与动画载入
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
namespace game::component::state {
|
||||
|
||||
void FallState::enter() {
|
||||
|
||||
playAnimation("fall"); // 播放下落动画
|
||||
}
|
||||
|
||||
void FallState::exit() {
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
namespace game::component::state {
|
||||
|
||||
void IdleState::enter() {
|
||||
|
||||
playAnimation("idle"); // 播放待机动画
|
||||
}
|
||||
|
||||
void IdleState::exit() {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
namespace game::component::state {
|
||||
|
||||
void JumpState::enter() {
|
||||
playAnimation("jump"); // 播放跳跃动画
|
||||
auto physics_component = player_component_->getPhysicsComponent();
|
||||
physics_component->velocity_.y = -player_component_->getJumpForce(); // 向上跳跃
|
||||
spdlog::debug("PlayerComponent 进入 JumpState,设置初始垂直速度为: {}", physics_component->velocity_.y);
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#include "player_state.h"
|
||||
#include "../player_component.h"
|
||||
#include "../../../engine/component/animation_component.h"
|
||||
#include "../../../engine/object/game_object.h"
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace game::component::state {
|
||||
|
||||
void PlayerState::playAnimation(const std::string& animation_name) {
|
||||
if (!player_component_) {
|
||||
spdlog::error("PlayerState 没有关联的 PlayerComponent,无法播放动画 '{}'", animation_name);
|
||||
return;
|
||||
}
|
||||
|
||||
auto animation_component = player_component_->getAnimationComponent();
|
||||
if (!animation_component) {
|
||||
spdlog::error("PlayerComponent '{}' 没有 AnimationComponent,无法播放动画 '{}'",
|
||||
player_component_->getOwner()->getName(), animation_name);
|
||||
return;
|
||||
}
|
||||
|
||||
animation_component->playAnimation(animation_name);
|
||||
}
|
||||
|
||||
} // namespace game::component::state
|
||||
@@ -30,6 +30,8 @@ public:
|
||||
PlayerState(PlayerState&&) = delete;
|
||||
PlayerState& operator=(PlayerState&&) = delete;
|
||||
|
||||
void playAnimation(const std::string& animation_name); ///< @brief 播放指定名称的动画,使用 AnimationComponent 的方法
|
||||
|
||||
protected:
|
||||
// 核心状态方法
|
||||
virtual void enter() = 0; ///< @brief 进入
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
namespace game::component::state {
|
||||
|
||||
void WalkState::enter() {
|
||||
|
||||
playAnimation("walk"); // 播放步行动画
|
||||
}
|
||||
|
||||
void WalkState::exit() {
|
||||
|
||||
Reference in New Issue
Block a user