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

Author Topic: Unable to initialize a reference of type....  (Read 1545 times)

0 Members and 1 Guest are viewing this topic.

P1T0

  • Newbie
  • *
  • Posts: 8
    • View Profile
Unable to initialize a reference of type....
« 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)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Unable to initialize a reference of type....
« Reply #1 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.
« Last Edit: April 19, 2020, 09:42:04 am by Laurent »
Laurent Gomila - SFML developer

P1T0

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Unable to initialize a reference of type....
« Reply #2 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
« Last Edit: April 19, 2020, 10:30:24 am by P1T0 »