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

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



Using spritecollide(sprite, group, dokill, collided = None) you can specify a collided function. They have one built in for a constant ratioÂpygame.sprite.collide_rect_ratio(). You can also specify your own function. If you do that you can specify a different variable of your sprite to be your collision rect.
Eg.
my_func = lambda left, right: pygame.sprite.collide_rect(left.scaled_rect, right.scaled_rect)
spritecollide(sprite, group, dokill, collided = my_func)

Jeff


On Thu, May 22, 2014 at 9:08 AM, Skorpio <skorpio2011@xxxxxxxx> wrote:
I don't blit the sprites at the rect/hitbox, Pygame does that. The sprites
are in a pygame.sprite.Group and when I call sprite_group.draw(screen) and
if the rects are scaled, their images get still blitted at the top left
corner of the rect. I'm using pygame.sprite.spritecollide() for the
collision detection.

Is there a way to give a sprite a additional hitbox?



--
View this message in context: http://pygame-users.25799.x6.nabble.com/pygame-Scaling-the-hitbox-rect-of-a-sprite-tp1227p1231.html
Sent from the pygame-users mailing list archive at Nabble.com.



--

   Jeffrey Kleykamp