SFML community forums

Help => Window => Topic started by: danersound on February 13, 2018, 12:10:56 pm

Title: problem with SFML blueprints "no match for call"
Post by: danersound on February 13, 2018, 12:10:56 pm
i just bought the "SFML blueprints" i was following the book when i found this "error" in the code and i dont know understand why ( see the picture ) some can help me?
Title: Re: problem with SFML blueprints "no match for call"
Post by: eXpl0it3r on February 13, 2018, 12:19:01 pm
CircleShape takes a float as constructor parameter (see the docs (https://www.sfml-dev.org/documentation/2.4.2/classsf_1_1CircleShape.php)).

However C++ should allow implicit conversion from int to float, so I'm not sure why it would error there.

The fix would probably be to use player(150.f). If that doesn't work, then there's a different issue and you'd need to show more code.
Title: Re: problem with SFML blueprints "no match for call"
Post by: danersound on February 13, 2018, 12:49:32 pm
yeah man, it still not working ( see first pic)
i try to change that line with other definition and it give me the same errore
Title: Re: problem with SFML blueprints "no match for call"
Post by: eXpl0it3r on February 13, 2018, 01:05:59 pm
Well you didn't just change what I suggested, but you changed more.

The player initialization can't be part of the window constructor (closing bracket before the player).
You can't call a function in the initialization list, but you have to use the constructor.
And the initialization list can't have a semicolon at the end.

Game::Game()
: window(sf::VideoMode(800, 600), "02_Game_Archi")
, player(150.f)
{
    player.setFillColor(sf::Color::Blue);
    player.Position(10.f, 20.f);
}

As you can see in my code, I also recommend to not use using namespace sf; and instead just specifying it. Makes it a lot easier to read the code and see what is an SFML type and what isn't.

(Also I don' think you want a width of 8000 ;) )
Title: Re: problem with SFML blueprints "no match for call"
Post by: danersound on February 13, 2018, 08:10:27 pm
I'm sorry to bother you ... i think i fix the problem but  the window dont want to stay open!

#include "Game.h"

void Game::run() {
        while (window.isOpen()){  //>>>>>>>>>> never get inside this
                processEvents();
                update();
                render();
        }
}
Game::Game() {
        sf::RenderWindow window(sf::VideoMode(800, 600), "Fast-Typing: The Game",sf::Style::Titlebar);
        sf::CircleShape player(150);
        player.setFillColor(sf::Color::Blue);
        player.setPosition(10, 20);
} ///// the window close after this

Game::~Game() {}
void Game::processEvents() {

        while (window.isOpen()) { // main Loop
                sf::Event event;
                while (window.pollEvent(event)) {
                        if (event.type == sf::Event::Closed) {
                                window.close();
                        }
                }
        }
}
void Game::update() {
}
void Game::render() {
        window.clear(sf::Color::Black);
        window.draw(player);
        window.display();
}
 


class Game {

public:
        Game();
        void run();
        virtual ~Game();

public:
        void processEvents();
        void update();
        void render();

        sf::RenderWindow window;
        sf::CircleShape player;
};

 



#include <iostream>
#include "Game.h"
using namespace std;

int main() {

        Game myGame;
        myGame.run();

        return 0;
}


 
Title: Re: problem with SFML blueprints &quot;no match for call&quot;
Post by: eXpl0it3r on February 13, 2018, 09:55:05 pm
You're now just creating a local variable with the game constructor. Once the constructor ends the local window variable gets destroyed again.