More pygame errors - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: More pygame errors (/thread-15080.html) Pages:
1
2
|
More pygame errors - PyEH - Jan-02-2019 Attempting to help my son. I cannot find the error or a reason Extract import png, os, pygame pygame.init() win = pygame.display.set_mode((1200,900)) pygame.display.set_caption("First Game") WalkRight = pygame.image.load(os.path.join('Red_Knight_Right.png')) WalkLeft = pygame.image.load(os.path.join('Red_Knight_left.png')) bg = pygame.image.load(os.path.join('game background.png')) char = pygame.image.load(os.path.join('Red Knight.png')) Stab_left = pygame.image.load(os.path.join('Red_Knight_stab_Left.png')) x = 500 y = 410 #varibles width = 40 height = 60 vel = 10 isJump = False jumpcount = 10 left = False right = False Stab_left = False def redrawGameWindow(): win.blit(bg, (0,0)) if left: win.blit(WalkLeft, (x,y)) elif right: win.blit(WalkRight, (x,y)) elif Stableft: win.blit(Stab_left) the image files are located in the same directory as the py file (C:\Users\******\Downloads\python_game_resourses\knight_game_combat_testing_not.py)I have also attempted the code as follow: WalkRight = pygame.image.load('Red_Knight_Right.png') WalkLeft = pygame.image.load('Red_Knight_left.png') bg = pygame.image.load('game background.png') char = pygame.image.load('Red Knight.png') Stab_left = pygame.image.load('Red_Knight_stab_Left') Same result I also attempted with .convert() Why is it not picking it up ? I have read the previous post on this topic and attempted all suggestions. RE: More pygame errors - metulburr - Jan-02-2019 tldr; pygame can't find your image in the place you said it would be the path of the file that is causing the problem is C:\Users\******\Downloads\python_game_resourses\knight_game_combat_testing_not.py . The way you have it with pygame loading and no second argument in os.path.join, you are loading the image in the same directoryC:\Users\******\Downloads\python_game_resourses\ . I am not sure if this is where you actually have the image or not?I am also not sure why you are using os.path.join as you are not joining any paths at all. RE: More pygame errors - PyEH - Jan-02-2019 Quote:C:\Users\******\Downloads\python_game_resourses\. I am not sure if this is where you actually have the image or not? The images are in the same directory as the .py module RE: More pygame errors - metulburr - Jan-02-2019 sorry i didnt read the text in between code snippets. you can try os.path.abspath instead what is png module? Quote:import png RE: More pygame errors - PyEH - Jan-02-2019 import pngI though reading https://www.pygame.org/docs/ref/image.html default support is bmp That I had a problem with unsupported image files and installed pypng module according to docs this is to load that module. This is not required as this is not the problem so can be removed RE: More pygame errors - metulburr - Jan-02-2019 What method did you use to install pygame? I have only had problems like that if i compiled pygame without the proper dependencies. You should not need an extra module to handle png images in pygame. RE: More pygame errors - metulburr - Jan-02-2019 Also is this file you are loading the images, your root file you are executing? IF this is a module imported to another file, and the images are in the same directory as this module, then it is going to fail. Example here (very last paragraph). RE: More pygame errors - PyEH - Jan-02-2019 Quote:What method did you use to install pygame? I used command line install : python -m pip install -U pygame --user I first had to update pip though python install pip --update (if I recall the exact command correctly) RE: More pygame errors - metulburr - Jan-02-2019 (Jan-02-2019, 08:38 PM)PyEH Wrote: That I had a problem with unsupported image files and installed pypng module according to docs this is to load that module. (Jan-02-2019, 09:09 PM)PyEH Wrote: python -m pip install -U pygame --user yes pygame should be able to handle that without anything additional. Is the file loading the images the root file that you are executing directly? RE: More pygame errors - PyEH - Jan-02-2019 Quote:Also is this file you are loading the images, your root file you are executing? IF this is a module imported to another file, and the images are in the same directory as this module, then it is going to fail. I believe this is a flat directory structure. I cannot see any root files as there are only the 2 .py files in that directory. I will need to see if there is a full app and get the full tree structure, although I do not believe this is the case (they are learning so I think he will keep it simple) |