SFML community forums

Help => Graphics => Topic started by: Uk Marine on March 02, 2014, 01:26:49 pm

Title: Yet another newbie question (regarding Textures and Sprites)
Post by: Uk Marine on March 02, 2014, 01:26:49 pm
Hello again everyone, so i'm still learning sfml and so far everything's going great, but i'm having a problem loading an image to the screen, here's the code:

sf::Texture texture;
        if (!texture.loadFromFile("C:\Users\User\Pictures\Photoshop Pictures\Ghost1.jpg"))
        {
                cout<<"Error#1 - Couldn't Load Texture files Correctly.\n";
        }
        sf::Sprite sprite(texture);
        sprite.setPosition(100.f,100.f);
        mWindow.clear();
        mWindow.draw(mPlayer);
        mWindow.display();

I don't know what i'm doing wrong, the picture isn't rendering.  :-\
Thank you.
Title: Re: Yet another newbie question (regarding Textures and Sprites)
Post by: Jesper Juhl on March 02, 2014, 01:32:16 pm
Your sprite is named "sprite" but you never draw it. Instead you draw something else named "mPlayer"..
Title: Re: Yet another newbie question (regarding Textures and Sprites)
Post by: Uk Marine on March 02, 2014, 01:35:08 pm
Thanks for the heads up, but it still says "fails to load image C:\Users\User\Pictures\Photoshop Pictures\Ghost1.jpg"
Title: Re: Yet another newbie question (regarding Textures and Sprites)
Post by: Jesper Juhl on March 02, 2014, 01:42:07 pm
Why didn't you mention that in the first post?

Anyway, are you 100% sure that path to the image is correct?
In the long run you probably don't want to use absolute paths, but rather paths rellative to the working directory of the program - makes it easier to move it to different machines  ;)
Title: Re: Yet another newbie question (regarding Textures and Sprites)
Post by: Hapax on March 02, 2014, 01:42:28 pm
it still says
You didn't mention that that was the error that you were getting.
You could try slashes in the location string. I think backslashes need to be escaped and therefore doubled.

You should use
[code=cpp]
tags to display code (it formats it so others can read it more easily).
Title: Re: Yet another newbie question (regarding Textures and Sprites)
Post by: Nexus on March 02, 2014, 01:44:13 pm
By the way: Golden Eagle, you can wrap tags in  [nobbc]  [/nobbc], then they have no effect:

 [code=cpp] code tag is not applied [/code]
Title: Re: Yet another newbie question (regarding Textures and Sprites)
Post by: Uk Marine on March 02, 2014, 01:49:03 pm
@Jesper, how can i move it to the working directory? do i just copy and paste it?
@Golden Eagle, used tags.
Title: Re: Yet another newbie question (regarding Textures and Sprites)
Post by: Hapax on March 02, 2014, 03:37:11 pm
By the way: Golden Eagle, you can wrap tags in  [nobbc]  [/nobbc], then they have no effect
That's exactly what I was looking for! :)

how can i move it to the working directory? do i just copy and paste it?
You can copy and paste, or move, or specify a different working directory. If you're sure that you have the correct absolute path and it's not working, you might want to fix that first :p (did you try slashes instead of backslashes?)