pygame中的属性错误 [英] AttributeError in pygame
本文介绍了pygame中的属性错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的错误跳到屏幕上的地方.有了这条消息:self.rect = self.image.get_rect()AttributeError: 'list' 对象没有属性 'get_rect'因为我想制作一个精灵
Here is where my error jumps onto the screen. With this message: self.rect = self.image.get_rect() AttributeError: 'list' object has no attribute 'get_rect' Because im trying to make a sprite
rigto = [pygame.image.load("img/Iconos/guy1.png"), pygame.image.load("img/Iconos/guy2.png"), pygame.image.load("img/Iconos/guy3.png"), pygame.image.load("img/Iconos/guy4.png")]
class Player:
def __init__(self, x, y, image):
self.image = image
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
jugador1 = Player(500, 500, rigto)
推荐答案
rigto
是一个图像列表(pygame.Surface
对象).您必须选择一张图片:
rigto
is a list of images (pygame.Surface
objects). You have to choose one image:
例如:
jugador1 = Player(500, 500, rigto[1])
或者,您可以管理类中的图像(例如动画):
Alternatively, you can manage the images in the class (e.g. for animations):
class Player:
def __init__(self, x, y, image_list):
self.image_list = image_list
self.count = 0
self.image = self.image_list[self.count]
self.rect = self.image.get_rect(topleft = (x, y))
def update(self)
self.count += 1
frame = self.count // 10
if frame >= len(self.image_list):
self.count = 0
frame = 0
self.image = self.image_list[frame]
jugador1 = Player(500, 500, rigto)
这篇关于pygame中的属性错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文