【问题标题】:Pygame Rect, what are the arguments?Pygame Rect,参数是什么?
【发布时间】:2015-01-04 21:35:13
【问题描述】:

我知道这听起来可能很愚蠢,但他们网站上的 pygame 文档说:

x = pygame.Rect(left,top,width,height)

但是,在我的程序中,我无法确定这是否正确,或者参数是否实际上是两组坐标。通过查看pygame源代码,我几乎没有经验。

【问题讨论】:

    标签: python arguments pygame collision


    【解决方案1】:

    Both of them work:

    pygame.Rect
    用于存储直角坐标的 pygame 对象
    Rect(left, top, width, height) -> Rect
    Rect((left, top), (width, height)) -> Rect
    Rect(object) -> Rect

    因此,如果您有坐标(x1, y1)(x2, y2),则以下两种方法都可以:

    pygame.Rect(x1, y1, x2-x1, y2-y1)
    
    pygame.Rect((x1, y1), (x2-x1, y2-y1))
    

    【讨论】:

    • 但我也可以放 Rect(x1,y1,x2,y2) 吗?如在两组坐标中
    • @AndrewLalis 不,应该是Rect(x1, y1, x2-x1, y2-y1)。第二对参数是宽度和高度。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-19
    • 2022-12-10
    • 1970-01-01
    • 2018-01-19
    • 1970-01-01
    相关资源
    最近更新 更多