So, (according to http://python-sfml.org/api/graphics.html#rectangle) I'm trying to do this :
player_rect.intersects(enemy_rect)
but then I get this:
File "graphics.pyx", line 188, in sfml.graphics.Rectangle.intersects (src/sfml\graphics.cpp:4442)
File "graphics.pyx", line 97, in sfml.graphics.Rectangle.__init__ (src/sfml\graphics.cpp:2420)
TypeError: __init__() takes at most 2 positional arguments (4 given)
What's going on? I'm guessing the API documentation has not been fully updated for SFML2 since the example code yields the same results, if so, what arguments (types) should I pass?
I'm getting the rectangles using global_bounds btw.
Edit: I'm using python 2.7
-something python bindings-specific?-
No that's a bug, thanks for discovering it.
Meantime, either override sf.Rectangle.intersects or maintain your own intersect function which should be as follow:
def intersects(self, rectangle):
# make sure the rectangle is a rectangle (to get its right/bottom border)
l, t, w, h = rectangle
rectangle = Rectangle((l, t), (w, h))
# compute the intersection boundaries
left = max(self.left, rectangle.left)
top = max(self.top, rectangle.top)
right = min(self.right, rectangle.right)
bottom = min(self.bottom, rectangle.bottom)
# if the intersection is valid (positive non zero area), then
# there is an intersection
if left < right and top < bottom:
return Rectangle((left, top), (right-left, bottom-top))
Tip: Create a file named "workaround.py" which lists and implements all these workarounds. Later, just delete it and you'll see what you have to change :)