SFML community forums

Help => General => Topic started by: P1T0 on April 19, 2020, 09:18:03 am

Title: Unable to initialize a reference of type....
Post by: P1T0 on April 19, 2020, 09:18:03 am
Hello,
i am having problems with this program,
it gives me three errors related to the "Draw" function,
unable to initialize a reference of type "sf :: Sprite &" (not qualified by const) with a value of type "sf :: RenderWindow",E0434 unable to initialize a reference of type "int &" (not qualified by const) with a value of type "sf :: Sprite",E0434 unable to initialize a reference of type "sf :: RenderWindow &" (not qualified by const) with a value of type "int",   and I don't know why,sorry for the inconvenience.


#include <SFML/Graphics.hpp>
#include <iostream>



using namespace sf;
using namespace std;

void Draw(RenderWindow& window, Sprite& g, Sprite& s);
void Move(int& keyTime, RenderWindow& window, Sprite& g,Sprite& s, Texture& t, Texture& p);
int main()
{
        int keyTime = 8;
        RenderWindow window(VideoMode(640, 420), "too awesome for a title");
        window.setFramerateLimit(60);
        Texture t;
        t.loadFromFile("images/Terrain.png");
        Sprite s(t);
        Texture p;
        p.loadFromFile("images/player.png");
        Sprite g(p);
       
        s.setTextureRect(IntRect(0, 0, 64, 64));
        s.setPosition(Vector2f(300,260));
        s.setTexture(t);
       
        g.setTextureRect(IntRect(0, 0, 20, 50));
        g.setPosition(Vector2f(window.getSize().x / 2, window.getSize().y / 2));
        g.setTexture(p);

       


        while (window.isOpen())
        {
                Event e;
                while (window.pollEvent(e))
                {
                        if (e.type == Event::Closed)
                                window.close();

                        if (e.KeyPressed && e.key.code == Keyboard::Escape)
                                window.close();
                }
               
                Move(g,keyTime,window,s,t,p);
                Draw(window,g,s);
               
        }


        return 0;
}


void Move(int& keyTime, RenderWindow& window, Sprite& g, Sprite& s, Texture& t, Texture& p)
{
        if (keyTime < 8)
                keyTime++;

        if (Keyboard::isKeyPressed(Keyboard::A) && keyTime >= 8 && g.getPosition().x > 0)
        {
                g.move(-10.f, 0.f);
                keyTime == 0;

        }
        if (Keyboard::isKeyPressed(Keyboard::D) && keyTime >= 8 && g.getPosition().x + p.getSize().x < window.getSize().x)
        {
                g.move(10.f, 0.f);
                keyTime == 0;
        }

       

        if (Keyboard::isKeyPressed(Keyboard::S) && keyTime >= 8 && g.getPosition().y + p.getSize().x < t.getSize().y)
        {
                g.move(0.f, 10.f);
                keyTime == 0;
        }
}

void Draw(RenderWindow& window, Sprite& g, Sprite& s)
{
        window.clear();

        //draw stuff...

        window.draw(g);
        window.draw(s);

        window.display();

}
 

(sorry for the bad english)
(sorry for the bothering)
Title: Re: Unable to initialize a reference of type....
Post by: Laurent on April 19, 2020, 09:40:28 am
The arguments that you pass to Move do not match its prototype.

Seriously, just read what you write, as well as the what the compiler tells you. Otherwise we'll see you everyday on the SFML forum with this kind of "problems".

That's the second issue that you have about passing arguments to a function. That's very basic C++ stuff, so I think you should not rush with SFML and learn / practice C++ more (with good resources -- ideally a book) before trying complicated things with SFML.
Title: Re: Unable to initialize a reference of type....
Post by: P1T0 on April 19, 2020, 10:26:17 am
You're right, I know c very well, but c ++ not too much, I will try to do simple things without SFML, and when I know this language better I will try to use SFML.
Have a nice day  :D