문제

I'm making a game in Pygame, and I have it so that if the character collides with a rect that it will push the character back a layer of pixels, creating a very small impassable boundary between it and the object. I was wondering that when I started to add art to it if I could have it covered up so it looked like a solid collision, or is there any way how a solid collision could function without their being that layer of pixels? Thanks in advance!

도움이 되었습니까?

해결책

Sure, just create a Rect that is a little bit bigger than the Rect of the Surface using inflate:

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. 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top