1 回答
TA贡献1765条经验 获得超5个赞
class enemy:
def __init__(self,x,y,height,width,color):
self.x = x
self.y = y
self.height = height
self.platforms = pygame.image.load("level5.png") #get the image so can find width
self.platforms = pygame.transform.scale(self.platforms,(self.platforms.get_width()*5,self.platforms.get_height()*5))
self.width = self.platforms.get_width() #get the width of the image
self.color = color
self.rect = pygame.Rect(x,y,height,width)
self.anim_index = 0
self.rect = self.platforms.get_rect(topleft = (self.x, self.y))
self.rect = pygame.Rect(x,y, self.platforms.get_width(), self.platforms.get_height())
图像和碰撞箱(你可以站立的部分)是两种不同的尺寸,你希望它们是一样的。所以不是给平台宽度。计算图像的宽度,以便您知道它们的大小相同
如果pygame.draw.rect(window, (0,0,0), self.rect)在 enemy 的 draw 方法中添加一个,那么你可以准确地看到玩家可以站立的位置,然后我们可以查看问题是图像还是碰撞
def draw:
self.rect.topleft = (self.x,self.y)
pygame.draw.rect(window,(0,0,0),self.rect)
window.blit(self.platforms,self.rect) #making sure that you draw the image on top of the square
添加回答
举报