更新子弹班。为什么子弹上升时y坐标值会减小?

时间:2019-08-14 19:16:55

标签: python

我创建了一个类,用于从我读的一本名为《 Python速成课程》的书中更新子弹在该外星人入侵游戏中的位置。我无法理解的是,为什么子弹在上升时对应于递减的y坐标?另外,为什么有必要从self.y中减去(1)的self.speed_factor呢?

此处https://imgur.com/corhigt

def update(self):
     """Move the bullet up the screen."""
     # Update the decimal position of the bullet.
      self.y -= self.speed_factor
     # Update the rect position.
      self.rect.y = self.y

def draw_bullet(self):
     """Draw the bullet to the screen."""
     pygame.draw.rect(self.screen, self.color, self.rect)

1 个答案:

答案 0 :(得分:0)

在(几乎)所有图形引擎中,X轴从左到右。但是, Y 轴从上到下,这与我们通常认为的Y轴相反。当您增加对象的Y坐标时,它将在屏幕上向下移动。