[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Scaling the hitbox/rect of a sprite



On ÄaÅ, 2014-05-22 at 03:47 -0700, Skorpio wrote:
> How can you scale the hitbox of a sprite? I tried self.rect =
> self.rect.inflate(-85, -20) and that scaled the rect correctly (to the
> center of the rect), but the game still takes the upper left corner of the
> rect as the blit position for the image/surface. That means the rect covers
> only the upper left part of the sprite, so that the left half of the sprite
> image can be hit and the right half can't be hit.

I'm not sure why you would use the hitbox as your blit position, if the
hitbox is a different size to the sprite.

I'd probably keep the rect for the sprite, and then when doing
hittesting, just do hit_test(self.rect.inflate(-85, -20)) or something
(never actually storing the scaled rect).

Attachment: signature.asc
Description: This is a digitally signed message part