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

Author Topic: SFML 2.0 Sprite is not carbonated (soda joke, sprites not working.)  (Read 3591 times)

0 Members and 1 Guest are viewing this topic.

MisterKpak

  • Newbie
  • *
  • Posts: 12
    • View Profile
I'm getting kinda mad at sfml 2.0. I set up my sprite stuff JUST LIKE the Docs said to. and i get "error: no matching function call for (sf::Sprite::Sprite(sf::Image&)

here's my code.

#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <cstdio>
#include <cstdlib>
#include <iostream>

int main(int argc, char**argv)
{
    sf::RenderWindow app(sf::VideoMode(800,640), "Sfml works!");
    sf::Text text("Welcome to SFML 2.0");
    text.setPosition(400,320);

    sf::Image terrain;
    if(terrain.loadFromFile("terrain.png"))
    {
        return EXIT_FAILURE;
    }


    sf::Sprite grass(terrain);
    grass.setTextureRect(IntRect(0,0,45,45);
    grass.setX(100,100);
    while(app.isOpen())
    {


        sf::Event Event;
        while(app.pollEvent(Event))
        {
            if(Event.type == sf::Event::Closed)
            {
                app.close();
            }
        }

    app.clear();
    app.draw(grass);
    app.draw(text);

    app.display();
    }
    return 0;
}
 

SargTeX

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: SFML 2.0 Sprite is not carbonated (soda joke, sprites not working.)
« Reply #1 on: June 20, 2012, 01:47:34 am »
According to the documentation, Image.loadFromFile() is returning true if the texture was loaded correctly. But you close the program if it was successfull:

    if(terrain.loadFromFile("terrain.png"))
    {
        return EXIT_FAILURE;
    }

You should change that ;)

So it seems your file could not be loaded. Is it readable? If you are using Linux, try "$ chmod 0777 terrain.png" (making the file world-readable via command shell). Otherwise, check the folder you have loaded the file into - maybe it's located on the wrong subfolder?

MisterKpak

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: SFML 2.0 Sprite is not carbonated (soda joke, sprites not working.)
« Reply #2 on: June 20, 2012, 01:52:27 am »
My problem is that sf::Sprite setImage() isnt working.
error: no matching function for call to 'sf::Sprite::Sprite(sf::Image&)'
That is the error i am recieving unpon compile.

I'm using windown ;)

SargTeX

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: SFML 2.0 Sprite is not carbonated (soda joke, sprites not working.)
« Reply #3 on: June 20, 2012, 02:04:25 am »
Sry for being stupid :D. Although, you should change that.
Is that the whole error message? And is that the code you are using?

I tried to run that on my comp, you are missing a closing bracket on the line
grass.setTextureRect(IntRect(0,0,45,45);

Also, according to the documentation there is no such method: "sf::Sprite setX()".

But the main error you are talking of seems to be somewhere else. Did you try to remove the other errors? Which IDE are you using, Visual Studio?

MisterKpak

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: SFML 2.0 Sprite is not carbonated (soda joke, sprites not working.)
« Reply #4 on: June 20, 2012, 02:05:24 am »
It stops compiling at sf::Sprite grass(terrain);

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Re: SFML 2.0 Sprite is not carbonated (soda joke, sprites not working.)
« Reply #5 on: June 20, 2012, 02:05:58 am »
According to the documentation, there is no constructor taking an sf::Image argument.
There is, however, a constructor taking a sf::Texture argument, and you can load a texture just like an image.

Read the examples on that page.

MisterKpak

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: SFML 2.0 Sprite is not carbonated (soda joke, sprites not working.)
« Reply #6 on: June 20, 2012, 02:08:26 am »
fixed that, thanks :D

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML 2.0 Sprite is not carbonated (soda joke, sprites not working.)
« Reply #7 on: June 20, 2012, 08:14:12 am »
Read the documentation for SFML 2, not 1.6.
Laurent Gomila - SFML developer