Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Errors while developing SFML Platformer engine  (Read 2936 times)

0 Members and 1 Guest are viewing this topic.

Lord Wolfram

  • Newbie
  • *
  • Posts: 11
  • Books give you knowledge, but knowledge is power!
    • ICQ Messenger - 136
    • View Profile
    • Andris Ivanovs - Programmer, Game Developer
Errors while developing SFML Platformer engine
« on: February 26, 2017, 07:45:21 pm »
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?


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Errors while developing SFML Platformer engine
« Reply #1 on: February 26, 2017, 08:52:09 pm »
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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Lord Wolfram

  • Newbie
  • *
  • Posts: 11
  • Books give you knowledge, but knowledge is power!
    • ICQ Messenger - 136
    • View Profile
    • Andris Ivanovs - Programmer, Game Developer
Re: Errors while developing SFML Platformer engine
« Reply #2 on: February 26, 2017, 09:15:34 pm »
Alright so how do I do that, I had tried few ways to make constructor but all ended  up wrong, so what kind of ways should I use to make that default constructor, and in which class?

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Errors while developing SFML Platformer engine
« Reply #3 on: February 27, 2017, 11:50:44 am »
time seems to also be some predefined thing which leads to an odd compiler error.

The "some predefined thing" is actually the standard header's time(), passed as a function pointer.