【发布时间】:2016-12-03 23:44:30
【问题描述】:
我在使用 pygame 获取曲面中心时遇到问题。当试图将它们放置在其他表面上时,它默认为表面的左上角。
为了说明我的意思,我写了一个简短的程序。
import pygame
WHITE = (255, 255, 255)
pygame.init()
#creating a test screen
screen = pygame.display.set_mode((500, 500), pygame.RESIZABLE)
#creating the canvas
game_canvas = screen.copy()
game_canvas.fill(WHITE)
#drawing the canvas onto screen with coords 50, 50 (tho its using the upper left of game_canvas)
screen.blit(pygame.transform.scale(game_canvas, (200, 200)), (50, 50))
pygame.display.flip()
#you can ignore this part.. just making the program not freeze on you if you try to run it
import sys
clock = pygame.time.Clock()
while True:
delta_time = clock.tick(60) / 1000
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
如果你运行这个程序,它会在屏幕(显示器)上的坐标 50、50 处绘制一个 200 x 200 白色的 game_canvas。但不是在坐标 50、50 处使用 game_canvas 的中心......是 50, 50。
那么如何使用 game_canvas 的中心将其放置在坐标 50、50 或任何其他给定坐标处?
【问题讨论】: