我一直在从事pygame的一个小项目.这是一款开销很大的2D游戏,但是如果玩家在对象后面,则我需要玩家在对象后面一层.如果播放器在对象的前面,则它需要在其前面.
for image, imagerect, imageypos in zip(blitimages, blitrects, blitypositions):
if realy < imageypos:
screen.blit(playerimage, playerimagerect)
screen.blit(image, imagerect)
if realy > imageypos:
screen.blit(image, imagerect)
screen.blit(playerimage, playerimagerect)
if realy == imageypos:
screen.blit(playerimage, playerimagerect)
screen.blit(image, imagerect)
那是我尝试过的方法,但是没有用.它始终将播放器显示在前面.
以供参考:
blitrects = [house1imagerect, house2imagerect, rock1imagerect]
blitimages = [house1image, house2image, rock1image]
blitypositions = [house1y, house2y, rock1y]
我最需要一种正确执行此操作的方法(这也很快),以及为什么这种方法行不通.如果愿意,我愿意发布更多代码部分,只需发表评论即可!提前致谢!
编辑:
完整代码:
import sys, pygame, math, random
pygame.init()
size = width, height = 1000,720
x = 0
y = 0
house1x = 500
house1y = 360
house2x = 1470
house2y = 360
rock1x = -100
rock1y = 300
scrollx = 0
scrolly = 0
screen = pygame.display.set_mode(size, pygame.DOUBLEBUF)
counter = 0
playercollideRect = pygame.rect.Rect((0, 0), (75, 25))
house1colli