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

Author Topic: How to load multiple images while key is being pressed  (Read 4218 times)

0 Members and 1 Guest are viewing this topic.

nevets_19

  • Newbie
  • *
  • Posts: 43
    • View Profile
How to load multiple images while key is being pressed
« 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

Code: [Select]

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

devlin

  • Full Member
  • ***
  • Posts: 128
    • View Profile
How to load multiple images while key is being pressed
« Reply #1 on: April 05, 2011, 03:49:29 pm »
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.

nevets_19

  • Newbie
  • *
  • Posts: 43
    • View Profile
How to load multiple images while key is being pressed
« Reply #2 on: April 05, 2011, 11:25:03 pm »
how do i do realitive paths XD
thanks for you help btw

JAssange

  • Full Member
  • ***
  • Posts: 104
    • View Profile
How to load multiple images while key is being pressed
« Reply #3 on: April 06, 2011, 02:35:15 am »
Quote from: "nevets_19"
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.

nevets_19

  • Newbie
  • *
  • Posts: 43
    • View Profile
How to load multiple images while key is being pressed
« Reply #4 on: April 06, 2011, 08:55:17 am »
oh, right so i just need to put the pictures in the same folder as my exe?

devlin

  • Full Member
  • ***
  • Posts: 128
    • View Profile
How to load multiple images while key is being pressed
« Reply #5 on: April 06, 2011, 09:10:11 am »
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.

nevets_19

  • Newbie
  • *
  • Posts: 43
    • View Profile
How to load multiple images while key is being pressed
« Reply #6 on: April 06, 2011, 09:51:27 am »
thats a better idea

thank you all for your help

 

anything