-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a system for animating sprites by manipulating their SpriteClip components based on frame data. Replace the bespoke rendering systems for the Ship and Wallop in the GracilisGame with the new Sprite and SpriteAnimation systems. Should AnimationFrames be a resource that is managed by the engine itself?
- Loading branch information
1 parent
ad73350
commit c632330
Showing
17 changed files
with
307 additions
and
115 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef GL_ADAGIO_SPRITEANIMATION_H | ||
#define GL_ADAGIO_SPRITEANIMATION_H | ||
|
||
#include "../../math/Rect.h" | ||
|
||
typedef unsigned char FrameIndex; | ||
|
||
struct AnimationFrame { | ||
double duration{0.0}; | ||
Adagio::RectI clip; | ||
}; | ||
|
||
struct SpriteAnimation { | ||
FrameIndex currentFrame{0}; | ||
FrameIndex frameLength{0}; | ||
bool loop{false}; | ||
bool done{false}; | ||
double timeOnCurrentFrame{0.0}; | ||
AnimationFrame* frames{nullptr}; | ||
}; | ||
|
||
#endif //GL_ADAGIO_SPRITEANIMATION_H |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "AnimateSprite.h" | ||
#include "../components/SpriteClip.h" | ||
#include "../components/SpriteAnimation.h" | ||
|
||
void AnimateSprite(entt::registry ®istry, Adagio::GameStats &stats, Adagio::StateMachine *state) { | ||
auto view = registry.view<SpriteClip, SpriteAnimation>(); | ||
for (auto [entity, clip, animation] : view.each()) { | ||
if (animation.frameLength > 0 && !animation.done) { | ||
animation.timeOnCurrentFrame += stats.getFrameDelta(); | ||
while (animation.timeOnCurrentFrame > animation.frames[animation.currentFrame].duration) { | ||
animation.timeOnCurrentFrame -= animation.frames[animation.currentFrame].duration; | ||
animation.currentFrame++; | ||
if (animation.currentFrame > animation.frameLength - 1) { | ||
if (animation.loop) { | ||
animation.currentFrame = 0; | ||
} else { | ||
animation.currentFrame = animation.frameLength - 1; | ||
animation.done = true; | ||
break; | ||
} | ||
} | ||
} | ||
Adagio::RectI &frameClip = animation.frames[animation.currentFrame].clip; | ||
clip.source.position.x = static_cast<float>(frameClip.position.x); | ||
clip.source.position.y = static_cast<float>(frameClip.position.y); | ||
clip.source.size.x = static_cast<float>(frameClip.size.x); | ||
clip.source.size.y = static_cast<float>(frameClip.size.y); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef GL_ADAGIO_ANIMATESPRITE_H | ||
#define GL_ADAGIO_ANIMATESPRITE_H | ||
|
||
#include "entt/entt.hpp" | ||
#include "../../graphics/SpriteBatch.h" | ||
#include "../../state/GameState.h" | ||
|
||
void AnimateSprite(entt::registry ®istry, Adagio::GameStats &stats, Adagio::StateMachine *state); | ||
|
||
#endif //GL_ADAGIO_ANIMATESPRITE_H |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.