【发布时间】:2019-10-31 12:33:15
【问题描述】:
我正在尝试在新表面上绘制一个箭头,这样我就可以旋转它,但是当我在我创建的新表面上绘制它时,它不会显示出来。
图标在放在game_display 表面时显示,但在放在player_icon 表面时不显示
import pygame
pygame.init()
white = (255,255,255)
black = (0,0,0)
grey = (175,175,175)
display_width = 1365
display_height = 700
game_display = pygame.display.set_mode((display_width, display_height))
pygame.display.set_caption("First Person Shooter")
game_display.fill(black)
clock = pygame.time.Clock()
player_rotation = 0
player_icon_height = 15
player_icon_width = 15
def draw_map():
player_icon = pygame.Surface((player_icon_width, player_icon_height))
player_icon.fill(black)
player_icon.set_colorkey(black)
icon_position = [[int(player_location_x),int(player_location_y - (player_icon_height / 2))],[int(player_location_x - (player_icon_width / 2)),int(player_location_y + (player_icon_height / 2))],[int(player_location_x),int(player_location_y)],[int(player_location_x + (player_icon_width / 2)),int(player_location_y + (player_icon_height / 2))]]
#This next line is the issue
pygame.draw.polygon(player_icon, white, icon_position)
blitted = game_display.blit(player_icon, [player_location_x - (player_icon_width / 2), player_location_y - (player_icon_height / 2)])
player_icon_rotated = pygame.transform.rotate(player_icon, player_rotation)
player_icon_rotated_rect = player_icon_rotated.get_rect()
player_icon_rotated_rect.center = blitted.center
game_display.blit(player_icon_rotated, player_icon_rotated_rect)
pygame.display.flip()
pygame.display.update()
draw_map()
它不会出现在新的表面上,但如果我将这条线替换为:
pygame.draw.polygon(game_display, white, icon_position)
那就没有问题了
【问题讨论】:
-
添加带有指针的屏幕并引用它...您在文本中迷失了我。还可以尝试通过简单的打印语句进行调试以查看一些值。这样,您可以在各个步骤检查您的输出。最坏的情况使用“import sys, print X, sys.stdout.flush()。也让它成为一个小的工作示例......使用 `__if name__ == main:.. 通常;p)
-
我只是不明白相同的声明如何在某些表面上可见,而在其他表面上却不可见。在这种情况下,我真的不明白 print 语句如何提供帮助。不过感谢您的帮助。
标签: python python-2.7 pygame pygame-surface