Jump to content

  • Log In with Google      Sign In   
  • Create Account


Pygame importing images


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Crazylegs830   Members   -  Reputation: 226

Like
0Likes
Like

Posted 06 January 2014 - 04:15 PM

I have been importing image into pygame like this:

image = pygame.image.load("C:\\Users\\user\\Desktop\\folder\\images\\Entities\\image.png")

Yet if I were to give this game to someone they can't play it, due to having a different user name. How do I fix this?



Sponsor:

#2 PeterF   Members   -  Reputation: 568

Like
2Likes
Like

Posted 06 January 2014 - 06:39 PM

You just need to make sure you know where the root folder of your game is - i.e. make sure you know the structure of the files and folders and they are all contained in a single folder. Say you have "C:\Users\user\Desktop\Game" and the entirety of your game, including the images and code, are in Game. Say your code is in "Game\code" and your image is in "Game\images\Entities", you can load the image with the following:
 

image = pygame.image.load("..\\images\\Entities\\image.png")

Where the ".." tells the computer to check what directory you're in right now and go up one level - in this case, the computer sees you're in the code directory, goes up to the Game directory, then follows the remaining path. If the image is in a subdirectory of the directory the code is in, just use a single ".". If you need to go up multiple directories, add a "..\\" for each level you need to go up.

That way it doesn't matter where on the computer the entire folder is stored, as long as the files are in the same position relative to one another.



#3 Crazylegs830   Members   -  Reputation: 226

Like
0Likes
Like

Posted 06 January 2014 - 08:20 PM

You just need to make sure you know where the root folder of your game is - i.e. make sure you know the structure of the files and folders and they are all contained in a single folder. Say you have "C:\Users\user\Desktop\Game" and the entirety of your game, including the images and code, are in Game. Say your code is in "Game\code" and your image is in "Game\images\Entities", you can load the image with the following:
 

image = pygame.image.load("..\\images\\Entities\\image.png")

Where the ".." tells the computer to check what directory you're in right now and go up one level - in this case, the computer sees you're in the code directory, goes up to the Game directory, then follows the remaining path. If the image is in a subdirectory of the directory the code is in, just use a single ".". If you need to go up multiple directories, add a "..\\" for each level you need to go up.

That way it doesn't matter where on the computer the entire folder is stored, as long as the files are in the same position relative to one another.

Ah, I see thank you very much!






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS