我有這個代碼運行良好,但唯一的問題是玩家的圖像是在其他圖像的後面,所以你不能看到玩家在哪裏。我如何製作它,讓玩家的圖像像背景圖層一樣位於該圖像的前方。我怎樣才能讓其他圖像出現在其他背景圖像的後面。例如像我這樣的背景樹:如何讓玩家的圖像在另一幅圖像的前面?
class Tree(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load('tree.png')
self.rect = self.image.get_rect()
和我有玩家的等級:
class Player(pygame.sprite.Sprite):
change_x = 0
change_y = 0
def __init__(self, x, y):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load('mapMover.png')
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
def changespeed_x(self,x):
self.change_x = x
def changespeed_y(self,y):
self.change_y = y
def update(self, barrier_list, Upcar_list, Downcar_list):
self.rect.x += self.change_x
barrier_hit_list = pygame.sprite.spritecollide(self, barrier_list, False)
Upcar_hit_list = pygame.sprite.spritecollide(self, Upcar_list, False)
Downcar_hit_list = pygame.sprite.spritecollide(self, Downcar_list, False)
for barrier in barrier_hit_list:
if self.change_x > 0:
self.rect.right = barrier.rect.left
else:
self.rect.left = barrier.rect.right
for Upcar in Upcar_hit_list:
if self.change_x > 0:
self.rect.right = Upcar.rect.left
Upcar.rect.x += 3
else:
self.rect.left = Upcar.rect.right
Upcar.rect.x -= 3
return
for Downcar in Downcar_hit_list:
if self.change_x > 0:
self.rect.right = Downcar.rect.left
Downcar.rect.x += 3
else:
self.rect.left = Downcar.rect.right
Downcar.rect.x -= 3
return
self.rect.y += self.change_y
barrier_hit_list = pygame.sprite.spritecollide(self, barrier_list, False)
Upcar_hit_list = pygame.sprite.spritecollide(self, Upcar_list, False)
Downcar_hit_list = pygame.sprite.spritecollide(self, Downcar_list, False)
for barrier in barrier_hit_list:
if self.change_y > 0:
self.rect.bottom = barrier.rect.top
else:
self.rect.top = barrier.rect.bottom
for Upcar in Upcar_hit_list:
if self.change_y > 0:
self.rect.top = Upcar.rect.bottom
Upcar.rect.y += 3
else:
self.rect.bottom = Upcar.rect.top
Upcar.rect.x -= 3
return
for Downcar in Downcar_hit_list:
if self.change_y > 0:
self.rect.top = Downcar.rect.bottom
Downcar.rect.y += 3
else:
self.rect.bottom = Downcar.rect.top
Downcar.rect.x -= 3
return
的Python 2.6,pygame的精靈,Windows 7的