当我运行代码时,图像显示在左上角附近.如何使图像显示在右上角附近?

我有一个问题.我在制造太空入侵者.太空入侵者在左上角产卵.正确旅行...放下...向左行驶..重复漂洗.

我的版本...我想让外星人在他们身边产卵.在右上角产卵...往下走……向左放下……往上走……向左放下……重复冲洗...

我把一切都做好了...但产卵点.我的外星人不想在右上角产卵.它们在左上角不停地产卵.代码运行得很好.舰队行动正常.但外星人不会在我想让它们产卵的地方产卵.有人介意帮我一把吗?

下面是献给外星人的整个文件.我可以调整什么来满足我的需求?

import pygame
from pygame.sprite import Sprite

class Alien(Sprite):
    """A class to represent a single alien in the fleet."""

def __init__(self, ai_game):
    """Initialize the alien and set its starting position."""
    super().__init__()
    self.screen = ai_game.screen
    self.sideways_settings = ai_game.sideways_settings
#   self.screen_rect = ai_game.screen.get_rect()

    # Load the alien image and set its rect attribute.
    self.image = pygame.image.load('images/alien.bmp')
    self.rect = self.image.get_rect()

    # Start each new alien near the top right of the screen.
    self.rect.x = self.rect.height
    self.rect.y = self.rect.width

    # Store the alien's exact vertical position.
    self.y = float(self.rect.y)
    self.x = float(self.rect.x)

def check_edges(self):
    """Return True if alien is at edge of screen."""
    screen_rect = self.screen.get_rect()
    if self.rect.bottom >= screen_rect.bottom or self.rect.top <= 0:
        return True

def update(self):
    """Move the alien up or down."""
    self.y += (self.sideways_settings.alien_speed *
                self.sideways_settings.fleet_direction)
    self.rect.y = self.y

#   def blitme(self):
#       """Draw the ship at its current location."""
#       self.screen.blit(self.image, self.rect)

推荐答案

屏幕的右上角坐标是(screen_rect.width, 0),而不是(0, 0):

# Start each new alien near the top right of the screen.
self.rect.x = screen_rect.width - self.rect.width
self.rect.y = 0

Python相关问答推荐

Django管理面板显示字段最大长度而不是字段名称

Pandas实际上如何对基于自定义的索引(integer和非integer)执行索引

Gekko:Spring-Mass系统的参数识别

在Polars(Python库)中将二进制转换为具有非UTF-8字符的字符串变量

我如何使法国在 map 中完全透明的代码?

Python中绕y轴曲线的旋转

如何在Polars中从列表中的所有 struct 中 Select 字段?

根据列值添加时区

旋转多边形而不改变内部空间关系

在pandas/python中计数嵌套类别

Gunicorn无法启动Flask应用,因为无法将应用解析为属性名或函数调用.'"'' "

Numpyro AR(1)均值切换模型抽样不一致性

BeautifulSoup:超过24个字符(从a到z)的迭代失败:降低了首次深入了解数据集的复杂性:

在用于Python的Bokeh包中设置按钮的样式

python的文件. truncate()意外地没有截断'

如何用FFT确定频变幅值

有没有一种方法可以在朗肯代理中集成向量嵌入

对于标准的原始类型注释,从键入`和`从www.example.com `?

是否需要依赖反转来确保呼叫方和被呼叫方之间的分离?

如何在不遇到IndexError的情况下将基数10的整数转换为基数80?