1

I'm working on a time based movement program in pygame. And I keep receiving this error.

Traceback (most recent call last):
  File "C:\Documents and Settings\Mohammad Raza\Desktop\Python     
Scripts\TimeBasedMovement.py", line 11, in <module>
    background = pygame.image.load(background_image_filename).convert()
error: Couldn't open Wolf.jpg

I thought perhaps I deleted the image, but I checked and the image is not deleted. It is saved as the name "Wolf" and stored as a JPEG image.

Here is the entire code below.

background_image_filename = 'Wolf.jpg'
sprite_image_filename = 'Cartoon.jpg'

import pygame
from pygame.locals import *
from sys import exit

pygame.init()
screen = pygame.display.set_mode((640,480),0,32)

background = pygame.image.load(background_image_filename).convert()
sprite = pygame.image.load(sprite_image_filename)

clock = pygame.time.Clock()

x = 0.
speed = 250

while True:

    for event in pygame.event.get():
        if event.type == QUIT:
            exit()

    screen.blit(background,(0,0))
    screen.blit(sprite,(x,100))

    time_passed = clock.tick()
    time_passed_seconds = time_passed_seconds / 1000.0

    distance_moved = time_passed_seconds * speed
    x += distance_moved

    if x > 640.:
        x -= 640.

    pygame.display.update()
M. Raza
  • 65
  • 1
  • 9

2 Answers2

0

Also make sure the image is in the current working directory.

fullname = os.path.join('data', name)
     image = pygame.image.load(fullname)
kotAPI
  • 387
  • 1
  • 7
  • 20
-2

Also it should be

time_passed_seconds = time_passed / 1000.
karthikr
  • 97,368
  • 26
  • 197
  • 188
Jacob
  • 1
  • True but that's not the issue that the OP is asking about. As helpful as it may be to point out other bugs in the OPs code, such help should be provided in comments as they don't actually answer the question that was asked. – Louis Oct 12 '14 at 22:50