MCPcopy Create free account
hub / github.com/EasyRPG/Player / Update

Method Update

src/sprite_actor.cpp:51–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49}
50
51void Sprite_Actor::Update() {
52 auto* battler = GetBattler();
53
54 if (!battler->IsHidden() && old_hidden != battler->IsHidden()) {
55 DoIdleAnimation();
56 }
57
58 old_hidden = battler->IsHidden();
59
60 ++cycle;
61
62 if (anim_state > 0) {
63 // Animations for allies
64 if (Player::IsRPG2k3()) {
65 UpdatePosition();
66
67 if (animation) {
68 // Is a battle animation
69 animation->SetInvert(battler->IsSpriteDirectionFlipped());
70 animation->Update();
71
72 if (animation->IsDone()) {
73 if (loop_state == LoopState_DefaultAnimationAfterFinish) {
74 DoIdleAnimation();
75 } else if (loop_state == LoopState_LoopAnimation) {
76 animation->SetFrame(0);
77 } else if (loop_state == LoopState_WaitAfterFinish) {
78 if (animation->GetFrames() > 0) {
79 animation->SetFrame(animation->GetFrames() - 1);
80 }
81 idling = true;
82 }
83 }
84
85 return;
86 }
87 // Is a battle charset animation
88 static const int frames[] = {0,1,2,1,0};
89 int frame = (battler->IsDefending() ? 0 : (normal_attacking ? std::min(2, cycle / 10) : frames[cycle / 10]));
90
91 if (battler->IsDirectionFlipped()) {
92 frame = 2 - frame;
93 }
94
95 if (frame == sprite_frame)
96 return;
97
98 const lcf::rpg::BattlerAnimation* anim = lcf::ReaderUtil::GetElement(lcf::Data::battleranimations, battler->GetBattleAnimationId());
99 if (!anim) {
100 Output::Warning("Invalid battler animation ID {}", battler->GetBattleAnimationId());
101 return;
102 }
103
104 const auto* ext = lcf::ReaderUtil::GetElement(anim->poses, anim_state);
105 if (!ext) {
106 Output::Warning("Animation {}: Invalid battler anim-extension state {}", anim->ID, anim_state);
107 return;
108 }

Callers

nothing calls this directly

Calls 12

minFunction · 0.85
IsHiddenMethod · 0.80
SetInvertMethod · 0.80
IsDoneMethod · 0.80
SetFrameMethod · 0.80
IsDefendingMethod · 0.80
IsDirectionFlippedMethod · 0.80
RectClass · 0.70
GetFramesMethod · 0.45
GetBattleAnimationIdMethod · 0.45
SetVisibleMethod · 0.45

Tested by

no test coverage detected