Pixel-perfect Sprite Collisions

In addition to the animation support last post, I have just added limited pixel-perfect collision detection between arbitrary pyglet sprites. You can see the results in the video, right after the break.

The collision detection only handles un-scaled, un-rotated sprites for the moment, but does handle animation. It first performs a rectangle-rectangle check to ensure fast rejection of non-overlapping sprites, and then takes the intersection of the bounding rectangles to minimise pixels tested.

So far it seems to be reasonably fast, despite being implemented entirely in un-optimised python. The example shown below performs several collision checks per frame, and still runs at a handy 60 fps.

Advertisements

3 comments

  1. That’s awesome, I’ve just begun to look into coding in pyglet and was wondering if someone had written any modules for pixel perfect collision. Sick demo.

  2. Pingback: Sprite collision revisited « swiftcoding


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s