【问题标题】:What is the difference between pygame sprite and surface?pygame sprite和surface有什么区别?
【发布时间】:2021-03-17 01:57:45
【问题描述】:

查看官方文档如下: 表面对象是表示矩形 2D 图像的对象。 Sprite 类旨在用作游戏中不同类型对象的基类。

都有image和rect属性,区别是sprite可以分组吗?

【问题讨论】:

标签: python pygame pygame-surface


【解决方案1】:

它们都有 image 和 rect 属性 [...]

不,这是错误的。 pygame.Surface 没有 rect 属性。 pygame.Surface.get_rect.get_rect() 返回一个与 Surface 对象大小相同的矩形,该矩形始终从 (0, 0) 开始,因为 Surface 对象没有位置。返回的矩形只是一个表面积大小的矩形,从 (0, 0) 开始。


我简短地说:pygame.Surface 没有位置,它只是一个位图。 pygame.sprite.Sprite 是一个由 Surface 对象和 pygame.Rect 对象组成的对象。 Sprite 的实例描述了图像在游戏窗口中的位置。

【讨论】:

    猜你喜欢
    • 2014-10-12
    • 1970-01-01
    • 2019-01-05
    • 1970-01-01
    • 2021-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多