python - pygame 无法重新定位图像
问题描述
我有一个位于屏幕中心的图像列表。
def relocate_images(self, images):
for image in images:
print('the center is ' + str(image.get_rect().center))
x_diff = int(self.width/2) - image.get_rect().x #self.width is the width of the screen
y_diff = int(self.height/2) - image.get_rect().y #self.height is the height of the screen
image.get_rect().move(x_diff, y_diff)
print('the center is ' + str(image.get_rect().center))
屏幕上显示的中心是相同的。所以价值没有签署到图像?
解决方案
图像没有位置。该方法image.get_rect()
返回一个与图像大小相同的矩形,但始终位于 (0, 0) 位置。您自己必须创建和管理所有图像的所有位置。我建议创建一个矩形列表,将其传递给该方法,并使用相同的矩形列表进行 blitting。或者,创建一个包含图像及其对应矩形的类。
推荐阅读
- java - 通过布尔检查按钮单击?
- node.js - 通过代理安装 npm 包以错误 407 结束
- android - 如何在Android中使用带有麦克风和播放音频的蓝牙耳机录制屏幕
- html - Angular Web 应用程序可以离线工作,但不能在线工作
- c++ - 如何为已渲染的多个 3D 模型创建多个模型矩阵?
- javascript - 如何更改 Angular 库组件中使用的垫卡的样式
- python - 如何在 Django 视图的外键列中分配字符串值而不是 id?
- flutter - 颤振文本小部件使用
- javascript - 如何更新 MongoDB 中深度嵌套的数组文档?
- flutter - 如何在 Flutter DataTable 中进行无限滚动?