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)