So I've been following this guy with his tutorial on 2D platformer
https://youtu.be/T6o5OlgsCew?t=185
And when you see him compiling for first time, he gets the animation, but for me I get some errors:
main.cpp:176:62: error: no matching function for call to 'Animation::Tick(time_t (__attribute__((__cdecl__)) &)(time_t*))'
stl_map.h:504:59: error: no matching function for call to 'Animation::Animation()'
The whole class looks like this:
// Animation class
class Animation
{
public:
std::vector<IntRect> Frames, Frames_flip;
float CurrentFrame, Speed;
bool Flip, IsPlaying;
Sprite sprite;
Animation(Texture &t, int x, int y, int w, int h, int Count, float speed, int Step)
{
Speed = speed;
sprite.setTexture(t);
CurrentFrame = 0;
IsPlaying = true;
Flip = false;
for (int i = 0; i < Count; i++)
{
Frames.push_back( IntRect(x+i*Step,y,w,h));
Frames_flip.push_back( IntRect(x+i*Step+w,y,-w,h));
}
}
void Tick(float Time)
{
if (!IsPlaying) return;
CurrentFrame += Speed * Time;
if (CurrentFrame> Frames.size())
CurrentFrame -= Frames.size();
int i = CurrentFrame;
sprite.setTextureRect( Frames[i] );
if (Flip) sprite.setTextureRect( Frames_flip[i] );
}
};
// Animation Manager Class
class AnimationManager
{
public:
String CurrentAnim;
std::map<String, Animation> animList;
AnimationManager()
{
}
void Create(String Name, Texture &t, int x, int y, int w, int h, int Count, float Speed, int Step)
{
animList[Name] = Animation(t,x,y,w,h,Count,Speed,Step);
CurrentAnim = Name;
}
void Draw(RenderWindow &window, int x = 0, int y = 0)
{
animList[CurrentAnim].sprite.setPosition(x,y);
window.draw(animList[CurrentAnim].sprite);
}
void Set(String name) { CurrentAnim = name; }
void flip (bool b) { animList[CurrentAnim].Flip = b; }
void tick(float Time) {animList[CurrentAnim].Tick(time); }
void pause () {animList[CurrentAnim].IsPlaying = false;}
void play () {animList[CurrentAnim].IsPlaying = true;}
};
So yeah, what's exactly going on here? Should I show the full code at some point?
void tick(float Time) {animList[CurrentAnim].Tick(time); }
Your parameter variable is called Time, but you're passing to the Tick function the variable time - notice the upper/lowercase first letter. time seems to also be some predefined thing which leads to an odd compiler error.
As for the second error, I'm not certain, but it might be that a value class needs to have a default constructor in order to be used within std::map.