refactor(animation): 重构动画方向处理逻辑
- 将翻转逻辑集中到Animation类中处理 - 添加spriteFrameOffsets_存储帧偏移量 - 改进角色动画方向切换时的表现 - 移除CharacterAnimation中的ApplyFlipRecursive方法 - 优化动画帧位置和旋转的计算方式
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
#include "character/CharacterAnimation.h"
|
||||
#include "character/CharacterAnimation.h"
|
||||
#include "character/CharacterObject.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <frostbite2D/2d/sprite.h>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstdio>
|
||||
|
||||
@@ -160,20 +158,16 @@ void CharacterAnimation::SetAction(const std::string& actionName) {
|
||||
|
||||
void CharacterAnimation::SetDirection(int direction) {
|
||||
direction_ = direction >= 0 ? 1 : -1;
|
||||
ApplyFlipRecursive(this, direction_ < 0);
|
||||
}
|
||||
|
||||
void CharacterAnimation::ApplyFlipRecursive(Actor* actor, bool flipped) const {
|
||||
if (!actor) {
|
||||
auto currentIt = actionAnimations_.find(currentActionTag_);
|
||||
if (currentIt == actionAnimations_.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto* sprite = dynamic_cast<Sprite*>(actor)) {
|
||||
sprite->SetFlippedX(flipped);
|
||||
}
|
||||
|
||||
for (const auto& child : actor->GetChildren()) {
|
||||
ApplyFlipRecursive(child.Get(), flipped);
|
||||
for (auto& animation : currentIt->second) {
|
||||
if (animation) {
|
||||
animation->SetDirection(direction_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user