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

Author Topic: [SOLVED] LoadFromFile Problem  (Read 5591 times)

0 Members and 1 Guest are viewing this topic.

torenf

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
[SOLVED] LoadFromFile Problem
« on: November 16, 2013, 07:15:41 pm »
Hi guys :D

I will write a little Jump and Run but i have 1 Problem
My Compiler say that sf::sprite dont have the member loadFromFile

Code:

int main()
{
    sf::RenderWindow Window(sf::VideoMode(800, 600, 32), "Blockjump");
    sf::Event Event;
    sf::Texture SFigur;
    sf::Sprite PImage;

    if (!PImage.loadFromFile("C:\\Programmiersachen\\sfml test\\bin\\Debug\\Spielfigur.png",sf::IntRect(0, 0, 128, 32)))
    {
    std::cout << "Spieler Image cant load!";
    }

    PImage.setTexture(SFigur);

    while (Window.isOpen())
    {
        while(Window.pollEvent(Event))
        {
            if(Event.type == Event.KeyPressed);
            {
                if(Event.key.code == sf::Keyboard::Escape)
                {
                    Window.close();
                }
            }

        }


        Window.clear(sf::Color(255,255,255));
        Window.draw(PImage);
        Window.display();
    }

return 0;
}

thats the Debugger:

In function 'int main()':|
error: 'class sf::Sprite' has no member named 'loadFromFile'|

« Last Edit: November 16, 2013, 10:26:26 pm by torenf »

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: LoadFromFile Problem
« Reply #1 on: November 16, 2013, 07:18:41 pm »
sf::Texture does.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: LoadFromFile Problem
« Reply #2 on: November 16, 2013, 07:19:51 pm »
Seriously don't guess at how to use a library. Read the official tutorials before posting code that doesn't work.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

torenf

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: LoadFromFile Problem
« Reply #3 on: November 16, 2013, 07:23:54 pm »
and what is now my problem ^^

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: LoadFromFile Problem
« Reply #4 on: November 16, 2013, 07:26:33 pm »
Your problem is described in the error message, why don't you read it?
Quote from: Compiler error
error: 'class sf::Sprite' has no member named 'loadFromFile'

As already stated: Read the tutorials in order to know how to use SFML. We like to help with specific questions, but you have to learn the basics first.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

torenf

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: LoadFromFile Problem
« Reply #5 on: November 16, 2013, 07:29:03 pm »
Now it says it dont find the Texture(Image)...

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: LoadFromFile Problem
« Reply #6 on: November 16, 2013, 07:53:08 pm »
For posting code please always use the [ code=cpp ] tag!

Well think, if the image can't be found ...... the application might be looking at the wrong place! ::)
The application will for a relative patch search in its working directory. Some IDEs set them to some other place than the actual binary.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: LoadFromFile Problem
« Reply #7 on: November 16, 2013, 07:58:07 pm »
For posting code please always use the [ code=cpp ] tag!

Beat me to it :P

Well think, if the image can't be found ...... the application might be looking at the wrong place! ::)
The application will for a relative patch search in its working directory. Some IDEs set them to some other place than the actual binary.

Looks like it is a full path to the file though, in which case I would suggest to check to make sure its actually there and that everything is spelled correctly.

Seriously though, the official tutorials are awesome. They're your best friend.
DSFML - SFML for the D Programming Language.

torenf

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: LoadFromFile Problem
« Reply #8 on: November 16, 2013, 08:03:04 pm »
Ok i can start my Programm but it says still that he cant find the image

#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
    sf::RenderWindow Window(sf::VideoMode(800, 600, 32), "Blockjump");
    sf::Event Event;
    sf::Texture SFigur;
    sf::Sprite PImage;

    if (!SFigur.loadFromFile("C:\\Programmiersachen\\sfml\\bin\\Debug\\Spielfigur.png",sf::IntRect(0, 0, 128, 32)))
    {
    std::cout << "Player Image cant load!";
    }

    PImage.setTexture(SFigur);

    while (Window.isOpen())
    {
        while(Window.pollEvent(Event))
        {
            if(Event.type == Event.KeyPressed);
            {
                if(Event.key.code == sf::Keyboard::Escape)
                {
                    Window.close();
                }
            }

        }


        Window.clear(sf::Color(255,255,255));
        Window.draw(PImage);
        Window.display();
    }

return 0;
}

he says in the console unable to open file!
« Last Edit: November 16, 2013, 08:07:49 pm by torenf »

torenf

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: LoadFromFile Problem
« Reply #9 on: November 16, 2013, 08:28:41 pm »
Please help me i put the image into the executable but it dont want ...

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: LoadFromFile Problem
« Reply #10 on: November 16, 2013, 08:34:12 pm »
Like I said before, make certain that the path to the image you are trying to open is valid and that the file exists there.

The Texture will be able to load the image if that is the case. It wouldn't say it can't find the file for no reason.
DSFML - SFML for the D Programming Language.

torenf

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: LoadFromFile Problem
« Reply #11 on: November 16, 2013, 08:46:57 pm »
He find the Image but hes unable to open :(

Salmon_Yo

  • Newbie
  • *
  • Posts: 17
    • View Profile
    • Email
Re: LoadFromFile Problem
« Reply #12 on: November 16, 2013, 10:10:08 pm »
Maybe you should try put your image into the directory of your project (near your source like "source.cpp") and write only
if (!SFigur.loadFromFile("Spielfigur.png"))
{
//errore
}
It works by myself..
« Last Edit: November 16, 2013, 10:32:54 pm by Salmon_Yo »

torenf

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: LoadFromFile Problem
« Reply #13 on: November 16, 2013, 10:26:12 pm »
Thanks so much :D

wintertime

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Re: [SOLVED] LoadFromFile Problem
« Reply #14 on: November 17, 2013, 12:45:47 pm »
And you may want to consider using a relative path with "/" not "\\" to have it easier to type and crossplatform.

 

anything