Pygame 就地方法 [英] Pygame in-place methodes
问题描述
in_place 函数与非 ip 函数有什么区别,它们为什么存在?什么时候应该使用move()
,inflate()
,什么时候使用move_ip()
,inflate_ip()
代码>?
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 move_ip()
,inflate_ip()
?
推荐答案
就地功能工作,很好,就地;它们会更改您调用它们的 Rect
,而非就地函数会根据更改返回 Rect
类的新实例.
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.
您可以在任何时候真正想要更改 Rect
时使用它们,例如你有一个 Sprite
并且想要移动它,你可以使用
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)
代替
s = SomeSpriteClass()
s.rect = s.rect.move(100, 0)
将 Sprite
向右移动 100 个像素.
to move the Sprite
100 pixels to the right.
当您不想实际更改 Rect
时,您可以使用非原位函数,例如当您只想进行一些计算时,例如实现相机功能.
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.
这篇关于Pygame 就地方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!