Coding the Animator class
First, let’s get the Animator
class up and running. The Animator
class will also be used by the FireballGraphics
class and the RainGraphics
class. It could be used by any class that wants to loop through set frames of animations. It can be configured for any set of animations as long as they are evenly sized, evenly spaced, and have the same vertical coordinates. The Animator
class can be configured by the code that uses it to reverse the animation order, which is useful when the player runs in the opposite direction as we will soon see. Reversing the animation can also produce a moon-walking effect but I will leave the reader to explore this possibility. The frame rate per second and the number of frames can also be determined at run time.
Create a class called Animator
(if you haven’t already).
Add this code to Animator.h
:
#pragma once
#include<SFML/Graphics.hpp>
using namespace sf;
class Animator
{
private:
IntRect m_SourceRect...