0
我想在MOUSEBUTTONCLICK被激活時不斷旋轉此圖像,但是當我運行MOUSEBUTTONCLICK時沒有任何事情發生。這是我嘗試過的代碼。旋轉鼠標按鈕上的圖像單擊pygame
while True:
'RotatingImg'
image_surf = pygame.image.load('imagefile')
image_surf = pygame.transform.scale(image_surf, (810,810))
image_surfpos = image_surf.get_rect()
screen.blit(image_surf, image_surfpos)
degree = 0
pygame.display.update()
for event in pygame.event.get():
'''Quit Button'''
if event.type == pygame.QUIT:
pygame.quit()
elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
## if mouse is pressed get position of cursor ##
screen.blit(target1, target1pos)
'RotatingImg'
image_surf = pygame.image.load('C:\\Users\Leyton\Documents\Coding Stuff\Python\Apps\Fan_blades.png')
image_surf = pygame.transform.scale(image_surf, (810,810))
image_surfpos = image_surf.get_rect()
screen.blit(image_surf, image_surfpos)
degree = 0
blittedRect = screen.blit(image_surf, image_surfpos)
'Get center of surf for later'
oldCenter = blittedRect.center
'rotate surf by amount of degrees'
rotatedSurf = pygame.transform.rotate(image_surf, degree)
'Get the rect of the rotated surf and set its center to the old center'
rotRect = rotatedSurf.get_rect()
rotRect.center = oldCenter
'Draw rotatedSurf with the corrected rect so it gets put in proper spot'
screen.blit(rotatedSurf, rotRect)
'Change the degree of rotation'
degree += 5
if degree > 0:
degree = 0
'Show the screen Surface'
pygame.display.flip()
'Wait 0 ms for loop to restart'
pygame.time.wait(0)
elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
screen.blit(target, targetpos)
如果名 == '主要': 遊戲()
我可以使用什麼樣的事件,讓圖片繼續旋轉而不是鼠標按鈕 – Leyton
沒有這樣的事件。你可能需要某種「is_pressed」變量,在鼠標向下/向上設置/取消設置,或每幀調用pygame.mouse.get_pressed()。 – user3757614