feat(动画系统): 实现动画系统基础功能
添加动画组件及相关数据结构,支持从PVF加载动画资源 实现动画播放、帧控制、插值逻辑等功能 更新主程序以测试动画系统
This commit is contained in:
81
Frostbite2D/include/frostbite2D/animation/animation.h
Normal file
81
Frostbite2D/include/frostbite2D/animation/animation.h
Normal file
@@ -0,0 +1,81 @@
|
||||
#pragma once
|
||||
|
||||
#include <frostbite2D/2d/actor.h>
|
||||
#include <frostbite2D/animation/animation_data.h>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace frostbite2D {
|
||||
|
||||
class Sprite;
|
||||
|
||||
class Animation : public Actor {
|
||||
public:
|
||||
struct ReplaceData {
|
||||
int param1 = 0;
|
||||
int param2 = 0;
|
||||
ReplaceData() = default;
|
||||
ReplaceData(int p1, int p2) : param1(p1), param2(p2) {}
|
||||
};
|
||||
|
||||
public:
|
||||
Animation();
|
||||
explicit Animation(const std::string& aniPath);
|
||||
Animation(const std::string& aniPath,
|
||||
std::function<std::string(std::string, ReplaceData)> additionalOptions,
|
||||
ReplaceData data);
|
||||
~Animation();
|
||||
|
||||
void Init(const std::string& aniPath);
|
||||
|
||||
void Update(float deltaTime) override;
|
||||
void OnAdded(Actor* parent);
|
||||
void SetVisible(bool visible);
|
||||
|
||||
public:
|
||||
void FlushFrame(int index);
|
||||
void Reset();
|
||||
animation::AniFrame GetCurrentFrameInfo();
|
||||
void SetFrameIndex(int index);
|
||||
void InterpolationLogic();
|
||||
|
||||
Vec2 GetMaxSize() const;
|
||||
|
||||
bool IsUsable() const { return usable_; }
|
||||
void SetUsable(bool usable) { usable_ = usable; }
|
||||
|
||||
int GetCurrentFrameIndex() const { return currentFrameIndex_; }
|
||||
int GetTotalFrameCount() const { return totalFrameCount_; }
|
||||
|
||||
public:
|
||||
bool usable_ = true;
|
||||
int currentFrameIndex_ = 0;
|
||||
int totalFrameCount_ = 0;
|
||||
float currentFrameTime_ = 0.0f;
|
||||
Ptr<Sprite> currentFrame_ = nullptr;
|
||||
float nextFrameDelay_ = 9999999.0f;
|
||||
|
||||
bool isLooping_ = true;
|
||||
|
||||
std::function<void(int)> changeFrameCallback_;
|
||||
std::function<void()> endCallback_;
|
||||
|
||||
std::vector<animation::AniFrame> frames_;
|
||||
std::vector<Ptr<Sprite>> spriteFrames_;
|
||||
|
||||
std::unordered_map<std::string, animation::AniFlag> animationFlag_;
|
||||
|
||||
std::string type_ = "normal";
|
||||
std::string aniPath_;
|
||||
|
||||
std::function<std::string(std::string, ReplaceData)> additionalOptions_;
|
||||
ReplaceData additionalOptionsData_;
|
||||
|
||||
Vec2 maxSize_ = Vec2::Zero();
|
||||
|
||||
std::vector<animation::AniFrame> interpolationData_;
|
||||
};
|
||||
|
||||
} // namespace frostbite2D
|
||||
Reference in New Issue
Block a user