image - Pygame 图像可以超出其矩形范围吗?

标签 image pygame collision rect

我正在用 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/

相关文章:

html - 水平显示无序列表

perl - 如何使用 Perl 以字节数组形式读取图像?

python - 如何在 Python 中检测无按键/无输入?

python - 需要帮助在 pygame 中创建按钮

android - 有没有一种简单的方法来检查两个 ImageViews 是否发生碰撞?

javascript - 为什么我的代理碰撞不起作用 (javascript)

image - CSS3 英雄图像 : Whats the best pixel dimension and Image Size for a full screen responsive background?

html - CSS图片重叠定位

python - Pygame 球弹跳模拟中的变量赋值

java - jBullet 例子