简体   繁体   English

pygame反向绘制项目

[英]pygame drawing items in inverse direction

The question is: 问题是:

I'm trying to make platform generator for my pygame project but the problem is when I create platforms the positioning in the pygame is inverse how could I solve that problem? 我正在尝试为我的pygame项目制作平台生成器,但是问题是当我创建平台时,pygame中的定位是相反的,我该如何解决该问题?

The code in my settings.py 我的settings.py中的代码

#Platform Generator
#Platforms(x, y, w, h)
PLATFORMS_LIST = []

for i in range(WIDTH):
    MAX_HEIGHT = random.randint(100, 120)
    PLATFORMS_LIST.append((i * 20, 300, 20, MAX_HEIGHT))

The code in sprites.py sprites.py中的代码

class Platforms(pygame.sprite.Sprite):
    def __init__(self, x, y, w, h):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.Surface((w, h))
        self.image.fill(GREEN)
        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y

代码输出

But I want the inverse of that green platforms. 但是我想要相反的绿色平台。

If the maximum height is 120, then you have to shift the items by the difference 120-MAX_HEIGHT to the bottom: 如果最大高度为120,则必须将项目相差120-MAX_HEIGHT移到底部:

MAX_HEIGHT = random.randint(100, 120)
# PLATFORMS_LIST.append((i * 20, 300, 20, MAX_HEIGHT))
PLATFORMS_LIST.append((i * 20, 300+120-MAX_HEIGHT, 20, MAX_HEIGHT))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM