pygame.rect中 Rect类 属性示意
生活随笔
收集整理的這篇文章主要介紹了
pygame.rect中 Rect类 属性示意
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
部分pygame.rect源代碼如下
class Rect(object):x: inty: inttop: intleft: intbottom: intright: inttopleft: Tuple[int, int]bottomleft: Tuple[int, int]topright: Tuple[int, int]bottomright: Tuple[int, int]midtop: Tuple[int, int]midleft: Tuple[int, int]midbottom: Tuple[int, int]midright: Tuple[int, int]center: Tuple[int, int]centerx: intcentery: intsize: Tuple[int, int]width: intheight: intw: inth: int__hash__: None # type: ignore示意圖
除 x,y wight,height以外, 實際英文單詞含義為 top, left bottom ,right 四條邊的坐標(取不為0的坐標) x,y : 矩形左上A點坐標, 與left ,top 相同 bottom,right : 右下B點坐標 其余屬性均為交點,或中點的x,y坐標組成的元組,望圖思意即可 增大圖形時考慮 wight,height(h,w屬性與其相同)測試代碼
import pygamedef test():""" 測試pygame.rect中Rect類的屬性 """# 初始化pygame,設置background pygame.init()screen = pygame.display.set_mode([1200, 600])pygame.display.set_caption("backgroundd")pygame.display.update()# 獲取分辨率,可以不加pygame.display.list_modes() # 獲取 surface 的外接矩形screen_rect = screen.get_rect()# 創建 Rect 實例 Rect(left, top, width, height)rect = pygame.Rect(20, 20, 100, 300)rect_color = [250, 250, 250]# rect.x = 0# rect.y = 0 # rect.bottom = 600# rect.right = 1200rect.h = 600while True:# background 填充顏色screen.fill([0, 0, 0])# 畫出外接矩形pygame.draw.rect(screen, rect_color, rect)# 更新整個 surface 對象pygame.display.flip()test()參考:
- pygame模塊參數匯總
- pygame詳解
總結
以上是生活随笔為你收集整理的pygame.rect中 Rect类 属性示意的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于混合使用智能指针和内置指针的自己的问
- 下一篇: 第七章_类_7.4 类的作用域(加了自己