我有一个鼠标精灵,每次游戏循环迭代时都会更新鼠标的x和y位置,但是我不太确定下面的错误消息是什么:“似乎'int'对象没有属性'mouse_x'像是将“自我”作为int对象,而“ mouse_x”作为其属性?]
import pygame
class mouse_sprite(pygame.sprite.Sprite):
def __init__(self, x, y, screen):
self.screen = screen
self.mouse_x = x
self.mouse_y = y
self.update_rect(self.mx, self.my)
def update_rect(self):
self.rect = pygame.Rect(self.mouse_x, self.mouse_y, 1, 1)
def update(self, x=None, y=None, screen=None):
**#ERROR: 'int' object has no attribute 'mouse_x' Line 24: self.mouse_x = x**
if x is not None:
self.mouse_x = x
if my is not None:
self.mouse_y = y
if screen is not None:
self.screen = screen
self.update_rect()
mouse = mouse_sprite
mx, my = pygame.mouse.get_pos()
mouse.update(mx, my)
您没有创建新对象。您只是在像静态方法一样调用类方法