Hello! I am new to pyglet (and writing games in general). I am
trying to figure out how to check if sprites overlap.
As an example, I wrote a program that creates 100 sprites, and draws
them with batch.draw() during on_draw(). And I scheduled an update
that, 60 times a second, randomly changes the sprites's x or y
position a few pixels each loop. This runs great, very fast.
Then, I compare each sprite to each other with this code I found on
someone's blog:
def collide(a, b):
if a.y + a.height < b.y:
return False
if a.y > b.y + b.height:
return False
if a.x + a.width < b.x:
return False
if a.x > b.x + b.width:
return False
return True
It works, but it's really, really slow (on a modern E8400 CPU). It
may be that this is a perfectly good technique, but I'm not using it
correctly...
Also, this treats all sprites like boxes, and wouldn't work well if
the sprite is supposed to be a circle, a ball, etc.
Does anyone have any code that handles this?
Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---