我正在用 Pygame 制作一个游戏,如果角色与矩形碰撞,它会将角色向后推一层像素,从而在它和对象之间创建一个非常小的不可逾越的边界。我想知道,当我开始向其中添加艺术时,是否可以将其覆盖,使其看起来像固体碰撞,或者是否有任何方法可以使固体碰撞在没有像素层的情况下发挥作用?提前致谢!
最佳答案
当然,只需使用inflate
创建一个比Surface
的矩形
稍大一点的矩形
即可。 :
Returns a new rectangle with the size changed by the given offset. The rectangle remains centered around its current center. Negative values will shrink the rectangle.
s = your_surface # the Surface containing your image .
r = s.get_rect() # the rect of the Surface.
c_r = r.inflate(2, 2) # the rect used for collision detection.
关于image - Pygame 图像可以超出其矩形范围吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17836330/