小智 8
pygame.mouse.set_cursor()
Pygame Cursor Constant Description
--------------------------------------------
pygame.SYSTEM_CURSOR_ARROW arrow
pygame.SYSTEM_CURSOR_IBEAM i-beam
pygame.SYSTEM_CURSOR_WAIT wait
pygame.SYSTEM_CURSOR_CROSSHAIR crosshair
pygame.SYSTEM_CURSOR_WAITARROW small wait cursor
(or wait if not available)
pygame.SYSTEM_CURSOR_SIZENWSE double arrow pointing
northwest and southeast
pygame.SYSTEM_CURSOR_SIZENESW double arrow pointing
northeast and southwest
pygame.SYSTEM_CURSOR_SIZEWE double arrow pointing
west and east
pygame.SYSTEM_CURSOR_SIZENS double arrow pointing
north and south
pygame.SYSTEM_CURSOR_SIZEALL four pointed arrow pointing
north, south, east, and west
pygame.SYSTEM_CURSOR_NO slashed circle or crossbones
pygame.SYSTEM_CURSOR_HAND hand
for example:
pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_HAND)
Run Code Online (Sandbox Code Playgroud)
如果您想从图像创建和使用自己的彩色自定义光标(并根据您在游戏中的位置显示不同的光标,例如在菜单或“游戏”中)。
这是程序:
这是一个简短的代码示例:
pygame.mouse.set_visible(False)
cursor_img_rect = cursor_img.get_rect()
while True:
# in your main loop update the position every frame and blit the image
cursor_img_rect.center = pygame.mouse.get_pos() # update position
gameDisplay.blit(cursor, cursor_rect) # draw the cursor
Run Code Online (Sandbox Code Playgroud)