pygame.mouse提供了一些方法获取鼠标设备当前的状态
pressed - get the state of the mouse buttons get the state of the mouse buttons
pygame.mouse.get_pos - get the mouse cursor position get the mouse cursor position
pygame.mouse.get_rel - get the amount of mouse movement get the amount of mouse movement
pygame.mouse.set_pos - set the mouse cursor position set the mouse cursor position
pygame.mouse.set_visible - hide or show the mouse cursor hide or show the mouse cursor
pygame.mouse.get_focused - check if the display is receiving mouse input check if the display is receiving mouse input
pygame.mouse.set_cursor - set the image for the system mouse cursor set the image for the system mouse cursor
pygame.mouse.get_cursor - get the image for the system mouse cursor get the image for the system mouse cursor
在下面的demo中,主要用到了:
pygame.mouse.get_pressed()
pygame.mouse.get_pos()
展示的效果:
游戏效果:
当鼠标经过窗口的时候,窗口背景颜色会随着鼠标的移动而发生改变,当鼠标点击窗口
会在控制台打印出是鼠标的那个键被点击了:左,右,滚轮
代码部分:
pygame.locals *
sys random *
= { : : : :
pygame.font:(
screen = pygame.display.set_mode((255,255),32 screen.fill((255,255,255
font = pygame.font.Font(,20 text = font.render(,True,(34,252,43
mouse_x,mouse_y = 1 event event.type == event.type == pressed_array =pressed()
index pressed_array)):
pressed_array[index]:
index == (pressed LEFT Button! index == 1 (pressed! index == 2 (pressed RIGHT Button! event.type ==
pos = mouse_x = mouse_y = pos[1
screen.blit(text,(40,100 pygame.display.update()
========================================================
More reading,and english is important.
I'm Hongten
大哥哥大姐姐,觉得有用打赏点哦!多多少少没关系,一分也是对我的支持和鼓励。谢谢。Hongten博客排名在100名以内。粉丝过千。Hongten出品,必是精品。
E | hongtenzone@foxmail.com B |
========================================================
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。