Pygame in-place methodes

前端 未结 1 1480
醉话见心
醉话见心 2021-01-21 03:36

What are the differences of in_place functions to non-ip ones and why do they exist? When should one use for instance move(),inflate() and when to use

相关标签:
1条回答
  • 2021-01-21 04:20

    The in place function work, well, in place; they change the Rect you call them on, while the non-in place functions return new instances of the Rect class with the according changes.

    You can use them anytime you actually want to change a Rect, e.g. you have a Sprite and want to move it, you can use

    s = SomeSpriteClass()
    s.rect.move_ip(100, 0)
    

    instead of

    s = SomeSpriteClass()
    s.rect = s.rect.move(100, 0)
    

    to move the Sprite 100 pixels to the right.

    You would use the non-in place functions when you don't want to actually change the Rect, e.g. when you only want to do some calculations, like implementing a camera function.

    0 讨论(0)
提交回复
热议问题