0

After updating SDL framework on Mac OSX 10.8.4 to fix fullscreen issues on the mac my images no longer load. Mostly just look at the top part of the function.

def load_image(name, colorkey=None):
    fullname = os.path.join('images',name)
    try:
        image = pygame.image.load(fullname)  # Tries loading image
    except pygame.error, message:            # If image load fails
        print "Cannot load image: ", fullname# return error to console
        raise SystemExit, message
    image = image.convert_alpha()            


    if colorkey is not None: 
        if colorkey is -1:
            colorkey = image.get_at((0,0))
        image.set_colorkey(colorkey, RLEACCEL)#new alpha value
    return image, image.get_rect()

This worked before the update but no longer does. Tried searching around and even updating again to no avail. I also tried...

fullname = os.path.join(os.sep, 'images',name)

...and then one image works then the second one does not. All folders and image names were tripled checked. I even changed the names and folders around still with no luck. Any other ideas?

EDIT: When I mentioned doesn't load images I meant the error command activates. Also checked correct directories by running os.getcwd .

Barker
  • 1
  • 1
  • Did you check that the current working directory is what you think it is? – Lennart Regebro Sep 10 '13 at 20:01
  • What do you mean by "no longer load"? The code here is supposed to print an error message -- what is it? – Ismail Badawi Sep 10 '13 at 20:01
  • Using the os.getcwd command it returns the correct working directory. I found out that the images load if they are in the EXACT same directory as the .py file. But using os.path.join will not let it use the 'images' directory. Also "no longer load" I meant it comes up with the error "Cannot load image". Thanks for your input! – Barker Sep 11 '13 at 06:13
  • As said, post the contents of `fullname` after the first line in your function. Most likely your paths are incorrect -- perhaps you are running your script from a different folder then before? You can get the directory name of your script by running `os.path.dirname(os.path.abspath(__file__))`. Plug that into your `os.path.join` and it should always work, regardless of your shell context. – jro Sep 11 '13 at 06:32
  • fullname = os.path.join(os.path.dirname(os.path.abspath("spriteattack2.py")),'images',name) I tried __file__ but came up with errors so I just plugged it in. It returns to the console. Cannot load image: /Users/Barker/Desktop/Game Tutorial/SpriteAttack/images/kid.jpg i checked the name of the folder. Checked it was there. This directory link is correct. Very strange. I also post the paths after the fullscreen as you suggested and it came up with the correct pathing. – Barker Sep 11 '13 at 16:11

0 Answers0