我画了一个象棋移动日志到一个矩形对象-然而,在一个特定的点后,文本离开底部,并被切断。我想知道是否有可能使矩形表面滚动,以便我可以看到整个移动日志。
下面是绘制移动日志的代码:
这就是我的意思
正如您在第21次移动后所看到的,日志从移动日志区域的底部脱落
def drawMoveLog(screen, gs, font): #draws move log
moveLogArea = p.Rect(BOARD_WIDTH, 0, MOVE_LOG_PANEL_WIDTH, MOVE_LOG_PANEL_HEIGHT)
p.draw.rect(screen , p.Color("gray"), moveLogArea)
moveLog = gs.moveLog
moveText = []
for i in range(0, len(moveLog), 2): #go through move log 2 at a time
moveString = "|| " + str(i//2 + 1) + ". " + str(moveLog[i]) + " "# to keep move 2 and 2 the same
if i + 1 < len(moveLog): # before i continue want to make sure black moved
moveString += str(moveLog[i + 1]) + " "
moveText.append(moveString)
movesPerRow = 1
padding = 5
lineSpacing = 4
textY = padding
#make 3 moves go in 1 line
for i in range(0, len(moveText), movesPerRow):
text = ""
for j in range (movesPerRow):
if i + j < len(moveText):
text += moveText[i+j]
textObject = font.render(text, True, p.Color('Black'))
textLocation = moveLogArea.move(padding, textY)
screen.blit(textObject, textLocation)
textY += textObject.get_height() + lineSpacing
1条答案
按热度按时间vwoqyblh1#
创建一个函数,以透明方式呈现文本
pygame.Surface
高到足以容纳全文。要创建透明曲面对象,必须设置标志pygame.SRCALPHA
:呈现全文并使用
pygame.Surface.subsurface
创建参照高度为的矩形区域的新曲面的步骤MOVE_LOG_PANEL_HEIGHT
.scroll参数是[0.0,1.0]范围内的值,用于线性滚动文本。当滚动为0.0时,显示文本的顶部,当滚动为1.0时,显示文本的底部:
比较
与
scroll = 0.0
以及scroll = 1.0
.