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

Author Topic: Draw two different sprites  (Read 1160 times)

0 Members and 1 Guest are viewing this topic.

P1T0

  • Newbie
  • *
  • Posts: 8
    • View Profile
Draw two different sprites
« 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)
« Last Edit: April 18, 2020, 08:01:07 pm by P1T0 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Draw two different sprites
« Reply #1 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.
Laurent Gomila - SFML developer

P1T0

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Draw two different sprites
« Reply #2 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.