MCPcopy Create free account
hub / github.com/OneLoneCoder/olcPixelGameEngine / TEST_Animate2D

Class TEST_Animate2D

examples/TEST_Animate2D.cpp:61–273  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59#include "utilities/olcUTIL_Animate2D.h"
60
61class TEST_Animate2D : public olc::PixelGameEngine
62{
63public:
64 TEST_Animate2D()
65 {
66 sAppName = "Animate2D Utility Test";
67 }
68
69 // These are the states the dude can exist in, we'll need these for physics
70 // and animation. The physics side of things moves the dude around according to state,
71 // while the animator chooses the frames based upon state and time
72 enum class DudeState: uint8_t
73 {
74 WALK_N, WALK_S, WALK_E, WALK_W, IDLE_STAND, LAUGH, CHEER, YES, NO
75 };
76
77 // !! - IMPORTANT - !!
78 // The animation set
79 olc::utils::Animate2D::Animation<DudeState> animDude;
80
81 // One big sprite containing all the graphics
82 olc::Renderable gfxAll;
83
84 // Small object to reprsent a dude walking around doing things
85 struct sWalkingDude
86 {
87 // Which dude overall out of graophic?
88 int32_t id = 0;
89 // Where are they?
90 olc::vf2d pos;
91 // What are they doing?
92 DudeState UserState = DudeState::IDLE_STAND;
93 // For how long should they do it?
94 float fTick = 0.0f;
95
96 // !! - IMPORTANT - !!
97 // Animation Token - links this object's state to animator. Note
98 // there is no 'ownership' or memory issues here, this is a token
99 // that the animator can use to quickly get to where it needs
100 // in order to return frames upon request for this object.
101 olc::utils::Animate2D::AnimationState animstate;
102 };
103
104 // Introducing.... The dudes!
105 size_t nDudes = 500;
106 std::vector<sWalkingDude> vDudes;
107
108public:
109 bool OnUserCreate() override
110 {
111 // For this appliaction I have a single image that contains
112 // 28x2 unique characters, each character contains 8 animations of 3
113 // frames each. Each frame is 26x36 pixels
114 gfxAll.Load("./assets/MegaSprite1.png");
115
116 // Thats A LOT of individual graphics, but they all follow a similar pattern
117 // because the asset was created usefully (take note certain popular asset creators)
118 // which means we can reuse the animation without needing to define it

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected