SFML community forums

Help => General => Topic started by: P1T0 on April 18, 2020, 07:52:09 pm

Title: Draw two different sprites
Post by: P1T0 on April 18, 2020, 07:52:09 pm
Hello everyone, I'm trying to make a small program in which a red rectangle (player) can walk on blocks of dirt (terrain) and when I try to put the player's sprite in the window.draw it gives me Gravity Code Description no instance overload function "sf :: RenderWindow :: draw" corresponding to the list of arguments.

There's the code:
#include <SFML/Graphics.hpp>
#include <iostream>



using namespace sf;
using namespace std;




int main()
{
        RenderWindow window(VideoMode(640, 480), "Title");
        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(20, 60));
        s.setTexture(t);

        cout << s.getPosition().x << endl;
        cout << s.getPosition().y << endl;

        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();
                }
                window.clear();
                window.draw(s,g);
       
                window.display();
        }


        return 0;
}
 

(sorry for the bad english)
(sorry for the bothering)
Title: Re: Draw two different sprites
Post by: Laurent on April 18, 2020, 08:49:27 pm
There's no version of draw that takes two sprites. Call it twice, with a single sprite each time.
Title: Re: Draw two different sprites
Post by: P1T0 on April 19, 2020, 08:13:04 am
Thank you!
 :D ;D :)
I had thought about it but I had thought but I had discarded the idea.