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

Author Topic: Program won't load images  (Read 16790 times)

0 Members and 1 Guest are viewing this topic.

rockstar8577

  • Newbie
  • *
  • Posts: 12
    • View Profile
Program won't load images
« on: March 09, 2010, 09:40:37 pm »
Code: [Select]

for (dcount = 0; dcount < 8; dcount++)
            {
                {
                    stringstream num;
                    num << "LD" << dcount << ".JPEG"; // uses the counter for the file name
                    temp = num.str();
                }

                cout  << temp << endl;
                if (!dimage[dcount].LoadFromFile(temp))
                    cout << "Error" << endl;
            }


For some reason it gets an error loading the image.
Post if you want to see more of the code.[/code]

Error which appears on the console
Failed to load image "LD1.JPEG". Reason : Unable to open file
Failed to load image "LD2.JPEG". Reason : Unable to open file
Failed to load image "LD3.JPEG". Reason : Unable to open file
Failed to load image "LD4.JPEG". Reason : Unable to open file
Failed to load image "LD5.JPEG". Reason : Unable to open file
Failed to load image "LD6.JPEG". Reason : Unable to open file
Failed to load image "LD7.JPEG". Reason : Unable to open file
Failed to load image "LD8.JPEG". Reason : Unable to open file
Failed to load image "LL1.JPEG". Reason : Unable to open file
Failed to load image "LL2.JPEG". Reason : Unable to open file
Failed to load image "LL3.JPEG". Reason : Unable to open file
Failed to load image "LL4.JPEG". Reason : Unable to open file
Failed to load image "LL5.JPEG". Reason : Unable to open file
Failed to load image "LL6.JPEG". Reason : Unable to open file

And the paths are correct because i had the files in a folder the first time, then i placed them in the source file location and still nothing.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Program won't images
« Reply #1 on: March 09, 2010, 09:54:01 pm »
Is your path really correct?

You could show us the SFML error message on the standard output (if any).
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

rockstar8577

  • Newbie
  • *
  • Posts: 12
    • View Profile
Program won't load images
« Reply #2 on: March 09, 2010, 10:19:58 pm »
The only thing im thinking, is that i get this warning from the compiler. But i don't see how it could be the problem because i did a program with a single image and that worked fine.

||Info: resolving vtable for sf::Spriteby linking to __imp___ZTVN2sf6SpriteE |
||warning: auto-importing has been activated without --enable-auto-import specified on the command line.|
||=== Build finished: 0 errors, 1 warnings ===|

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Program won't load images
« Reply #3 on: March 09, 2010, 11:14:08 pm »
The reason of the warning is that you didn't define SFML_DYNAMIC.

I really think that your paths are incorrect ;)
Try to load something else to be sure (like a text file with std::ifstream).
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Program won't load images
« Reply #4 on: March 09, 2010, 11:16:23 pm »
If the paths are really really correct (please check that again, I hate nothing more than guessing around if the problem is obvious :D), might the images be broken? Does the same thing work if you use BMP instead of JPG format?

Did you recently update SFML and forgot to recompile the library? Any other library inconsistences? If nothing helps, rebuild everything you use.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

rockstar8577

  • Newbie
  • *
  • Posts: 12
    • View Profile
Program won't load images
« Reply #5 on: March 10, 2010, 12:29:01 am »
Ok so i found out that my images are broken according to SFML only though. So i have to see whats wrong with them.

model76

  • Full Member
  • ***
  • Posts: 231
    • View Profile
Program won't load images
« Reply #6 on: March 10, 2010, 01:17:08 am »
I have also run into this problem before, and my solution is to use PNGs.

They are fairly small, although not as small as jpeg, but capable of better image quality, and they even have an alpha channel, if you should need it.

rockstar8577

  • Newbie
  • *
  • Posts: 12
    • View Profile
Program won't load images
« Reply #7 on: March 10, 2010, 02:07:58 am »
Ahh, well thank you. I was wondering why there was a white background for my files. Ohh and now i have a new problem. If i hit the down key, which is the only one coded for the change in the sprite. It just moves the sprite to the top left corner.

model76

  • Full Member
  • ***
  • Posts: 231
    • View Profile
Program won't load images
« Reply #8 on: March 10, 2010, 02:14:10 am »
Hehe, I'd love to help you, but you will need to post some code ;)

rockstar8577

  • Newbie
  • *
  • Posts: 12
    • View Profile
Program won't load images
« Reply #9 on: March 10, 2010, 02:30:51 am »
Ok
Keypress up:
Code: [Select]


void mdown()
        {
            if (dcount == 7)
                dcount = 0;
            else
                dcount += 1;

            ucount = 0;
            lcount = 0;
            rcount = 0;
        }

--------------------------------------------------------

if (App.GetInput().IsKeyDown(sf::Key::Down))
        {
            avatar.mdown();
            Sprite = avatar.dimage[avatar.dcount];
            Sprite.Move(0,  100 * ElapsedTime);
        }


I used the dashes to separate them because they are at 2 different parts.
I run the mdown function to change the count. Set the image to the new image.

model76

  • Full Member
  • ***
  • Posts: 231
    • View Profile
Program won't load images
« Reply #10 on: March 10, 2010, 03:00:05 am »
I think your problem is here:
Code: [Select]
Sprite = avatar.dimage[avatar.dcount];I am guessing that dimage is some sort of container of sprites, and when you do a_sprite = another_sprite, you simply copy all the information of another_sprite into a_sprite - including its position.

What you want to do, is to change the image that your sprite points to, instead. You can do this by
Code: [Select]
Sprite.SetImage(Image);Of course, that means that your dimage container should now hold images, instead of sprites.

rockstar8577

  • Newbie
  • *
  • Posts: 12
    • View Profile
Program won't load images
« Reply #11 on: March 10, 2010, 03:37:34 am »
Yea i found that out while looking through the wiki after posting it xD .
Well now i just got to get rid of the white background, which im trying to do with png's like you said. Then i need to add i think a 50 millisecond delay to make it transition smoothly to the next set image.

Edit:
So how do i set the alpha transparency?

model76

  • Full Member
  • ***
  • Posts: 231
    • View Profile
Program won't load images
« Reply #12 on: March 10, 2010, 04:30:06 am »
The white background is there because you saved the picture with a white background. If you want to get rid of it, you should open it with your image editor and remove the background from the image (set it to transparent).

Alternatively, you could use color keying to remove it in your program, but I don't remember if SFML has that functionality. It probably does.
But be aware that color keying will remove EVERY pixel with the color key you choose (that would be white in your case), not just the ones in the "background".
That is one of the reasons using the alpha channel is a big step up from that technique.

rockstar8577

  • Newbie
  • *
  • Posts: 12
    • View Profile
Program won't load images
« Reply #13 on: March 10, 2010, 09:37:45 pm »
well i tried setting it to transparent, and well i wasnt good at doing that. So i just ended up deleting the background of the sprite. Well it works for the most part but not there is lines coming out from the sprite. If someone could possibly look at the sprite and see maybe why its happening.

Nvm, it was just the images. Well now i have it working, i just need to do diagonal movements which im guessing you just do when buttons pressed equal this and this.