屏幕窗口-pygame.display
.set_mode((width,height),flags=0) #设置窗口大小
flags:pygame.RESIZABLE 可调,pygame.NOFRAME 无边界,pygame.FULLSCREEN 全屏。
.Info() #获得窗口信息,.current_w,.current_h 获得宽度和高度。
.get_active() #最小化时False
.set_icon(surface) #设置图标
.set_caption(“text”) #设置标题
.flip() #重绘整个窗口
.update() #重绘变化区域
位图操作-pygame.transform
加载:surface=pygame.image.load(<路径>).convert_alpha() #加载alpha通道
缩放:surface=pygame.transform.scale(surface,size) #平滑缩放 smoothscale
提取:surface=surface.subsurface([left,top,width,height])
翻转:surface=pygame.transform.flip(surface,xbool,ybool)
旋转:surface=pygame.transform.rotate(surface,angle)
生成rect:rect=surface.get_rect()
绘制:screen.blit(surface,rect/(x,y))
移动:rect=rect.move(x,y)
事件响应-pygame.event
.get() #获取事件列表
.poll() #获取单一事件
.clear() #清空事件列表
.set_blocked(type/typelist) #禁止事件被保存
.set_allowed(type/typelist) #只允许事件被保存
.post() #产生自定义事件 (type,dict)
事件类型-event.type
pygame.QUIT #退出
pygame.ACTIVEEVENT #窗体变化
pygame.KEYDOWN #键盘按下
pygame.KEYUP #键盘抬起
pygame.MOUSEMOTION #鼠标移动
pygame.MOUSEBUTTONDOWN #鼠标按下
pygame.MOUSEBUTTONUP #鼠标抬起
具体事件-event.key
键盘:
pygame.unicode #编码
pygame.K_小写字母/ESCAPE/UP/DOWN/… #名称
pygame.mode #或运算
鼠标:
pygame.pos #坐标
pygame.button #左/中/右 1/2/3
pygame.rel #相对运动(在pygame.MOUSEMOTION下)
绘制图形-pygame.draw
rect(surface,color,rect,width=0<填充>) #矩形
polygon(surface,color,pointlist<顶点列表>,width=0) #多边形
circle(surface,color,pos,radius,width=0) #圆
ellipse(surface,color,rect,width=0) #椭圆
arc(surface,color,rect,start_angle,stop_angle,width=0) #椭圆弧
line(surface,color,start_pos,end_pos,width=0<填充>) #直线
lines(surface,color,close<封闭>,pointlist,width=0<填充>) #连续线
绘制文字-pygame.freetype
字体文件 C:/windows/Fonts .ttf,.ttc
import pygame.freetype
Font=pygame.freetype.Font(<字体>,<字号>)
Font.render_to(surface,dest<位置>,text,fgcolor=None<字体颜色>,bgcolor=None<背景颜色>,rotation=0<角度>,size=0<字号>)
色彩机制-pygame.Color
pygame.Color(name)
pygame.Color(r,g,b,) #浅蓝(193,210,240)
pygame.Color(rgbvalue)
.normalize #归一到(0,1)
————————————————
版权声明:本文为CSDN博主「Mr_Stutter」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_53715621/article/details/113973626
版权