ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
AnimationComponent类 参考

动画组件 更多...

#include <AnimationComponent.h>

类 AnimationComponent 继承关系图:
Behavior Component

Public 成员函数

 AnimationComponent ()
 ~AnimationComponent () override
void onAttach () override
void onStart () override
 首次 update 前执行一次
void onUpdate () override
 每帧执行
void onDestroy () override
void addAnimation (const std::string &name, std::unique_ptr< Animation > animation)
void play (const std::string &name)
void stop ()
void pause ()
void resume ()
void play (const std::string &name, const SpriteSheet &sheet, const std::vector< int > &frames, float duration=0.1f, bool loop=true)
 用数字帧索引直接设置并播放一段动画
bool isPlaying () const
bool isPaused () const
const std::string & getCurrentAnimationName () const
Public 成员函数 继承自 Behavior
 Behavior ()=default
 ~Behavior () override=default
void onCreate () override
void onAttach () override
void onDetach () override
void onDestroy () override
bool isStarted () const
 onStart 是否已执行过
void setStarted (bool isStarted)
Public 成员函数 继承自 Component
 Component ()
virtual ~Component ()=default
 Component (const Component &)=delete
Componentoperator= (const Component &)=delete
 Component (Component &&)=delete
Componentoperator= (Component &&)=delete
GameObjectgetOwner () const
bool isRegistered () const

额外继承的成员函数

Protected 属性 继承自 Behavior
bool m_isStarted = false
Protected 属性 继承自 Component
GameObjectm_owner = nullptr
bool m_isRegistered = false

详细描述

动画组件

继承 Behavior,由 BehaviorSystem 每帧调用 onUpdate 推进当前动画时间, 并把当前帧的源矩形 (SDL_FRect) 回写到同 GameObject 上的 SpriteRenderer。

典型用法(三点式 sprite-sheet): Shit::SpriteSheet sheet(4, 8, 32, 32); // 4行8列,每帧32×32 auto* anim = go->addComponent<AnimationComponent>(); anim->play("walk", sheet, {0,1,2,3,4,5}, 0.1f, true); // 全局帧索引数组

或手工添加已构造好的 Animation: anim->addAnimation("walk", std::move(walkAnim)); anim->play("walk");

构造及析构函数说明

◆ AnimationComponent()

AnimationComponent ( )

◆ ~AnimationComponent()

~AnimationComponent ( )
override

成员函数说明

◆ addAnimation()

void addAnimation ( const std::string & name,
std::unique_ptr< Animation > animation )

◆ getCurrentAnimationName()

const std::string & getCurrentAnimationName ( ) const
inline

◆ isPaused()

bool isPaused ( ) const
inline

◆ isPlaying()

bool isPlaying ( ) const
inline

◆ onAttach()

void onAttach ( )
overridevirtual

重载 Component .

◆ onDestroy()

void onDestroy ( )
overridevirtual

重载 Component .

◆ onStart()

void onStart ( )
overridevirtual

首次 update 前执行一次

重载 Behavior .

◆ onUpdate()

void onUpdate ( )
overridevirtual

每帧执行

重载 Behavior .

◆ pause()

void pause ( )

◆ play() [1/2]

void play ( const std::string & name)

◆ play() [2/2]

void play ( const std::string & name,
const SpriteSheet & sheet,
const std::vector< int > & frames,
float duration = 0.1f,
bool loop = true )

用数字帧索引直接设置并播放一段动画

按 frames 中的索引从 sheet 切出条帧,构造一个 Animation 并以 name 登记/覆盖后播放。 若 name 已存在则替换。

参数
name动画名(用作登记与 play 索引)
sheet精灵图集,提供行列网格切割
frames想要播放的全局帧索引序列(如 {0,1,2,3,5,8},可不连续)
duration每帧持续时间(秒)
loop是否循环

◆ resume()

void resume ( )

◆ stop()

void stop ( )

该类的文档由以下文件生成: