TypeError:“module”对象在pygam中不可调用

2024-04-23 09:00:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我是pygame新手,我有这个错误,请帮帮我。在

    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()

我有个错误:

^{pr2}$

Tags: fromimageimportconvert错误displayfilenamepygame
2条回答

你的问题是你的事件.获取循环。我在我的游戏中使用了一个类似的方法,这是正确的方法,但是你的下几行缩进错误

x, y = pygame.mouse.get_pos()
        x -= mouse_cursor.get_width()/2
        y -= mouse_cursor.get_height()/2
        screen.blit(mouse_cursor, (x, y)) 

需要无凹痕或向后移动

你在做:

background = pygame.image.load(backgrounf_image_filename).convert()
mouse_cursor = pygame.image(mouse_image_filename).convert_alpha()

在第二条指令中,您忘记了load您的映像,结果是调用了模块而不是函数。在

就这么做吧:

^{pr2}$

相关问题 更多 >