[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Scaling the hitbox/rect of a sprite
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] Scaling the hitbox/rect of a sprite
- From: Sam Bull <sam.hacking@xxxxxxxx>
- Date: Thu, 22 May 2014 13:39:20 +0100
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Thu, 22 May 2014 08:35:30 -0400
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=sent.com; h= message-id:subject:from:to:date:in-reply-to:references :content-type:mime-version; s=mesmtp; bh=0pi0zZCPHnK+780Fy4fT4O8 /v0s=; b=FFu85HjOhzdohWARaBvRUvxPOCXM6yc6JHW+lyCE4uOvMhR2NLPhZ4G p/EiegIH6fDRyOc0NWOVY/HzePkzUPQUerpcVEuCw1SUeiJOBhvSHwj/Xdd7c+lh /h0lQE3aY6uDKR3tvmE/jrAgVeV8uBVQU6JEYuC49XOYyNZbiEsY=
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:subject:from:to:date :in-reply-to:references:content-type:mime-version; s=smtpout; bh=0pi0zZCPHnK+780Fy4fT4O8/v0s=; b=Evf5li2vzEToUDrmc2kaO3dLdRss /bg3S5gp2UHqxPY+xyPrqvA6Ervo6y/VBGRpGiYEnDDb9HYG61B8nPv8AdwHWd5/ ofhKWgsychmma0+6pGgdUu7UGji72XdEKM5wX2ZQ071XrNl/V4hbakoACk1xaiI9 v59gEdL+sAw5W9o=
- In-reply-to: <1400755639908-1227.post@xxxxxxxxxxxxx>
- References: <1400755639908-1227.post@xxxxxxxxxxxxx>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
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