0
你好,我正在嘗試爲塔防遊戲創建塔,但每次我選擇一個新塔時,舊塔會被移除。我不希望這被刪除,我相信有一個簡單的方法來做到這一點,但我找不到它。這是我的代碼。感謝您的任何幫助。pygame有多個相同的圖像
def displayTower():
global bx, by
click = pygame.mouse.get_pressed()
Background.blit(redTower, (mx-bx,my-by))
Background.blit(redTower, (530,650))
while intro == 1:
mousePos = pygame.mouse.get_pos()
mousePressed = pygame.mouse.get_pressed()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
if 530 < mousePos[0] < 590 and 650 < mousePos[1] < 710:
if mousePressed[0] == 1:
clicked = True
if clicked == True:
mx, my = pygame.mouse.get_pos()
bx = 30
by = 30
if mousePressed[0] == 0:
Background.blit(redTower, (mx-bx,my-by))
tx = mx - bx
ty = my - by
clicked = False
displayTower()
還有更多的代碼和displayTower()在我的代碼中的while循環我只是在提出問題時出錯,並且有pygame.display.update()以及 –
葉背景只是地圖對於塔防遊戲 –
首先使用事件而不是拔出鼠標狀態。然後回來一個更好的代碼。那麼你也需要,screen.blit(background,(0,0)); pygame.display.flip() – Dalen