ShitEngine 1.4.2
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
AnimationClip.h
浏览该文件的文档.
1#pragma once
2
3#include "../Core/Core.h"
5
6#include <nlohmann/json.hpp>
7
8#include <string>
9#include <vector>
10
11namespace Shit
12{
16 std::string texturePath;
18 };
19
32 std::string name;
33 std::string texturePath;
34 int rows = 0;
35 int cols = 0;
36 float frameWidth = 0.0f;
37 float frameHeight = 0.0f;
38 float margin = 0.0f;
39 float spacing = 0.0f;
40 float duration = 0.1f;
41 bool loop = true;
42 bool isDefault = false;
43 std::vector<int> frames;
44 std::vector<float> frameDurations;
46 std::vector<AnimFrame> frameSprites;
48
50 nlohmann::json toJson() const;
52 bool fromJson(const nlohmann::json &j);
55 };
56}
#define SHIT_API
定义 Core.h:14
定义 AnimationClip.h:12
动画帧(参考 Unity:每帧引用一个 Sprite = 纹理路径 + 源矩形) texturePath 空 = 沿用 SpriteRenderer 当前纹理(兼容动态 play(name,...
定义 AnimationClip.h:15
Rect rect
定义 AnimationClip.h:17
std::string texturePath
定义 AnimationClip.h:16
动画剪辑(可序列化数据,P28)
定义 AnimationClip.h:31
int rows
网格行数
定义 AnimationClip.h:34
nlohmann::json toJson() const
序列化到 JSON(载体 / .anim 资产)
bool isDefault
是否默认播放(onStart 自动播放)
定义 AnimationClip.h:42
std::string texturePath
精灵表纹理路径(编辑器预览与运行时切帧用)
定义 AnimationClip.h:33
void expandFramesToSprites()
若 frameSprites 为空且 frames 非空,用网格+texturePath 展开填充 frameSprites(幂等)
int cols
网格列数
定义 AnimationClip.h:35
float frameWidth
单帧宽(像素)
定义 AnimationClip.h:36
float frameHeight
单帧高(像素)
定义 AnimationClip.h:37
bool loop
是否循环
定义 AnimationClip.h:41
float duration
统一每帧时长(秒,无 frameDurations 时使用)
定义 AnimationClip.h:40
std::vector< float > frameDurations
每帧独立时长(秒,可选)。长度与 frameSprites 等长时逐帧生效, 否则回退到统一 duration(Dope Sheet 时间轴,P29)
定义 AnimationClip.h:44
std::vector< AnimFrame > frameSprites
运行时真值:每帧 {纹理路径 + 源矩形},支持跨图集多纹理。 空 = 旧格式,由 fromJson 从 frames+网格+texturePath 展开
定义 AnimationClip.h:46
std::string name
剪辑名(play/索引用)
定义 AnimationClip.h:32
std::vector< int > frames
全局帧索引序列(旧格式 / 单图集快捷选帧)
定义 AnimationClip.h:43
float margin
网格左上留白(像素)
定义 AnimationClip.h:38
float spacing
帧间距(像素)
定义 AnimationClip.h:39
bool fromJson(const nlohmann::json &j)
从 JSON 解析(失败返回 false,字段保持默认)
Rectangle struct (float precision), with SDL_FRect conversion
定义 Math.h:10