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
添加回答
舉報