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

Author Topic: Yet another newbie question (regarding Textures and Sprites)  (Read 2405 times)

0 Members and 1 Guest are viewing this topic.

Uk Marine

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Yet another newbie question (regarding Textures and Sprites)
« 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.
« Last Edit: March 02, 2014, 01:47:04 pm by Uk Marine »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Yet another newbie question (regarding Textures and Sprites)
« Reply #1 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"..

Uk Marine

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: Yet another newbie question (regarding Textures and Sprites)
« Reply #2 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"
« Last Edit: March 02, 2014, 01:38:10 pm by Uk Marine »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Yet another newbie question (regarding Textures and Sprites)
« Reply #3 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  ;)

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Yet another newbie question (regarding Textures and Sprites)
« Reply #4 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).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Yet another newbie question (regarding Textures and Sprites)
« Reply #5 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]
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Uk Marine

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: Yet another newbie question (regarding Textures and Sprites)
« Reply #6 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.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Yet another newbie question (regarding Textures and Sprites)
« Reply #7 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?)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*