I'm new in pygame and I have that error please help me.
backgrounf_image_filename = 'ubisoft.jpg'
mouse_image_filename = 'cursor.png'
import pygame
from pygame.locals import *
from sys import exit
pygame.init()
screen = pygame.display.set_mode((640, 480), 0, 32)
pygame.display.set_caption("Hello World!")
background = pygame.image.load(backgrounf_image_filename).convert()
mouse_cursor = pygame.image(mouse_image_filename).convert_alpha()
and I have that error:
Traceback (most recent call last):
File "C:/Users/ziyaa/PycharmProjects/pygame/helloworld.py", line 13, in <module>
mouse_cursor = pygame.image(mouse_image_filename).convert_alpha()
TypeError: 'module' object is not callable
Process finished with exit code 1
You're doing:
background = pygame.image.load(backgrounf_image_filename).convert()
mouse_cursor = pygame.image(mouse_image_filename).convert_alpha()
In the second instruction, you forgot to load
your image, resulting in calling the module instead of the function.
Just do:
mouse_cursor = pygame.image.load(mouse_image_filename).convert_alpha()
Your problem is your for event.get loop. I use a similar one for my games, and its the right approach however you have your next few lines indented wrong
x, y = pygame.mouse.get_pos()
x -= mouse_cursor.get_width()/2
y -= mouse_cursor.get_height()/2
screen.blit(mouse_cursor, (x, y))
needs to be unidented or moved back
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.