SFML community forums
Help => Graphics => Topic started by: nevets_19 on April 05, 2011, 03:17:00 pm
-
Hello i have been worknig on a zelda like game and i have run into a problem, i have got a bunch of images names linkeast1 linkeast2, etc up to 10, i want it to load them while i am holding down the right key to represent walking, however when i do this i get an output in the console window saying cannot load image unable to open file. I am using .PNG images and this is my code
if(Main.GetInput().IsKeyDown(sf::Key::Right)){
player.LoadFromFile ("C:/Users/Gaming/Documents/Visual Studio 2008/Projects/Programing/SFML/Steven Games/Zelda/Link/LinkEast.png");
player.CreateMaskFromColor(sf::Color(255, 0, 255, 255));
Player.Move (3.0, 0);
player.LoadFromFile ("C:/Users/Gaming/Documents/Visual Studio 2008/Projects/Programing/SFML/Steven Games/Zelda/Link/LinkEast1.png");
player.CreateMaskFromColor(sf::Color(255, 0, 255, 255));
Player.Move (3.0, 0);
player.LoadFromFile ("C:/Users/Gaming/Documents/Visual Studio 2008/Projects/Programing/SFML/Steven Games/Zelda/Link/LinkEast2.png");
player.CreateMaskFromColor(sf::Color(255, 0, 255, 255));
Player.Move (3.0, 0)
player.LoadFromFile ("C:/Users/Gaming/Documents/Visual Studio 2008/Projects/Programing/SFML/Steven Games/Zelda/Link/LinkEast3.png");
player.CreateMaskFromColor(sf::Color(255, 0, 255, 255));
Player.Move (3.0, 0)
player.LoadFromFile ("C:/Users/Gaming/Documents/Visual Studio 2008/Projects/Programing/SFML/Steven Games/Zelda/Link/LinkEast4.png");
player.CreateMaskFromColor(sf::Color(255, 0, 255, 255));
Player.Move (3.0, 0)
player.LoadFromFile ("C:/Users/Gaming/Documents/Visual Studio 2008/Projects/Programing/SFML/Steven Games/Zelda/Link/LinkEast5.png");
player.CreateMaskFromColor(sf::Color(255, 0, 255, 255));
Player.Move (3.0, 0)
player.LoadFromFile ("C:/Users/Gaming/Documents/Visual Studio 2008/Projects/Programing/SFML/Steven Games/Zelda/Link/LinkEast6.png");
player.CreateMaskFromColor(sf::Color(255, 0, 255, 255));
Player.Move (3.0, 0)
player.LoadFromFile ("C:/Users/Gaming/Documents/Visual Studio 2008/Projects/Programing/SFML/Steven Games/Zelda/Link/LinkEast7.png");
player.CreateMaskFromColor(sf::Color(255, 0, 255, 255));
Player.Move (3.0, 0)
player.LoadFromFile ("C:/Users/Gaming/Documents/Visual Studio 2008/Projects/Programing/SFML/Steven Games/Zelda/Link/LinkEast8.png");
player.CreateMaskFromColor(sf::Color(255, 0, 255, 255));
Player.Move (3.0, 0)
player.LoadFromFile ("C:/Users/Gaming/Documents/Visual Studio 2008/Projects/Programing/SFML/Steven Games/Zelda/Link/LinkEast9.png");
player.CreateMaskFromColor(sf::Color(255, 0, 255, 255));
Player.Move (3.0, 0)
}
Thank you for any help, this was just a guess on how to do this so it might be wrong =D i am pretty bad at SFML
-
You really, really, really *really* want to preload these before the level begins rather than while pressing the key. Then you use an animationCounter to keep track of which to display and switch them out accordingly.
However, that being said. It would be a lot more efficient to store all those images within the same image (called a sprite sheet) and then update the SubRects of a Sprite to the different images, rather than changing image over and over.
Also, the above won't really do much - visually. You're not rendering the sprite, you're just loading all those images all at once and moving him all those steps all at once.
As for why they can't be loaded - have you double-checked that the path you gave is correct? (there's an m missing in Programming, for instance). Also - by using absolute paths like this - nobody else will ever be able to play your game unless they recreate that exact path structure. Try to use relative paths instead.
-
how do i do realitive paths XD
thanks for you help btw
-
how do i do realitive paths XD
thanks for you help btw
Relative paths just mean you only specify directory structure starting within the folder of your executable.
-
oh, right so i just need to put the pictures in the same folder as my exe?
-
You could do that, and just use the filename.
Or you put them in a subfolder (like say "data") and use "data/myfile.png" to load it.
-
thats a better idea
thank you all for your help