Hi guys,
I was wondering if there was any interest in adding an AABB (axis aligned
bounding box) attribute to the sprite class. It's just a couple lines of
code, and it would make doing simple collision checks easier for new users.
A simple property like this would suffice:
@property
def aabb(self):
return (self._x, self._y,
self._x + (self._texture.width * self._scale),
self._y + (self._texture.height * self._scale))
It would be pretty easy to check if two sprites are overlapping. Here is a
simple function that returns True/False (a few more calculations would tell
you exact details of the overlap):
def is_overlapping(first_aabb, second_aabb):
aleft, atop, aright, abottom = first_aabb
bleft, btop, bright, bbottom = second_aabb
# An overlap has occured if ALL of these are True, otherwise return
False:
return bleft < aright and bright > aleft and btop < abottom and bbottom
> atop
Would something like this be considered out of scope for inclusion? Just
looking for feedback. It's easy enough to do this manually, or subclass
Sprite, but I'm thinking it would be nice for new users. I see a lot of new
Pygame users taking advantage of the colliderect and other built in
functions that are build on top of the SDL Rect classes. Maybe it would
make pyglet easier for those types of users. Maybe even include a few
simple collision checks as part of the Sprite class itself would be usuful.
For example :
>>> player.is_overlapping(enemy)
True
>>>player.get_overlap(enemy)
(0, 0, 2, 5)
-Ben
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.