我正在尝试重新创建一个幻灯片拼图,我需要将文本打印到以前绘制的矩形精灵。这就是我设置它们的方式:
class Tile(Entity):
def __init__(self,x,y):
self.image = pygame.Surface((TILE_SIZE-1,TILE_SIZE-1))
self.image.fill(LIGHT_BLUE)
self.rect = pygame.Rect(x,y,TILE_SIZE-1,TILE_SIZE-1)
self.isSelected = False
self.font = pygame.font.SysFont('comicsansms',22) # Font for the text is defined
这就是我画它们的方式:
def drawTiles(self):
number = 0
number_of_tiles = 15
x = 0
y = 1
for i in range(number_of_tiles):
label = self.font.render(str(number),True,WHITE) # Where the label is defined. I just want it to print 0's for now.
x += 1
if x > 4:
y += 1
x = 1
tile = Tile(x*TILE_SIZE,y*TILE_SIZE)
tile.image.blit(label,[x*TILE_SIZE+40,y*TILE_SIZE+40]) # How I tried to print text to the sprite. It didn't show up and didn't error, so I suspect it must have been drawn behind the sprite.
tile_list.append(tile)
这就是我尝试添加 Rect 的方式(用鼠标单击它时):
# Main program loop
for tile in tile_list:
screen.blit(tile.image,tile.rect)
if tile.isInTile(pos):
tile.isSelected = True
pygame.draw.rect(tile.image,BLUE,[tile.rect.x,tile.rect.y,TILE_SIZE,TILE_SIZE],2)
else:
tile.isSelected = False
isInTile:
def isInTile(self,mouse_pos):
if self.rect.collidepoint(mouse_pos): return True
我究竟做错了什么?