Module AggiEngine.contactlistener

Expand source code
from Box2D import b2ContactListener, b2Contact, b2Manifold, b2Vec2


class ContactListener(b2ContactListener):
    """
    Receives contact information from Box2D and passes it along to the GameObjects in the collision.
    """

    def __init__(self):
        b2ContactListener.__init__(self)

    def BeginContact(self, contact: b2Contact) -> None:
        """
        Called when two Box2D bodies collide and calls their beginContact(otherBody) methods
        ``contact:`` The contact event
        """
        bodyA = contact.fixtureA.body
        bodyB = contact.fixtureB.body
        bodyA.userData.beginContact(bodyB)
        bodyB.userData.beginContact(bodyA)

    def EndContact(self, contact: b2Contact) -> None:
        """
        Called when two Box2D bodies collide and calls their endContact(otherBody) methods
        ``contact:`` The contact event
        """
        bodyA = contact.fixtureA.body
        bodyB = contact.fixtureB.body
        bodyA.userData.endContact(bodyB)
        bodyB.userData.endContact(bodyA)

    def PreSolve(self, contact: b2Contact, manifold: b2Manifold) -> None:
        """
        Called before Box2D handles a contact while the bodies are still overlapping
        """
        bodyA = contact.fixtureA.body
        bodyB = contact.fixtureB.body
        bodyA.userData.preSolve(bodyB, manifold)
        bodyB.userData.preSolve(bodyA, manifold)

    def PostSolve(self, contact: b2Contact, impulse: b2Vec2) -> None:
        """
        Called after Box2D handles a contact while the bodies are no longer overlapping
        """
        bodyA = contact.fixtureA.body
        bodyB = contact.fixtureB.body
        bodyA.userData.postSolve(bodyB, impulse)
        bodyB.userData.postSolve(bodyA, impulse)

Classes

class ContactListener

Receives contact information from Box2D and passes it along to the GameObjects in the collision.

Expand source code
class ContactListener(b2ContactListener):
    """
    Receives contact information from Box2D and passes it along to the GameObjects in the collision.
    """

    def __init__(self):
        b2ContactListener.__init__(self)

    def BeginContact(self, contact: b2Contact) -> None:
        """
        Called when two Box2D bodies collide and calls their beginContact(otherBody) methods
        ``contact:`` The contact event
        """
        bodyA = contact.fixtureA.body
        bodyB = contact.fixtureB.body
        bodyA.userData.beginContact(bodyB)
        bodyB.userData.beginContact(bodyA)

    def EndContact(self, contact: b2Contact) -> None:
        """
        Called when two Box2D bodies collide and calls their endContact(otherBody) methods
        ``contact:`` The contact event
        """
        bodyA = contact.fixtureA.body
        bodyB = contact.fixtureB.body
        bodyA.userData.endContact(bodyB)
        bodyB.userData.endContact(bodyA)

    def PreSolve(self, contact: b2Contact, manifold: b2Manifold) -> None:
        """
        Called before Box2D handles a contact while the bodies are still overlapping
        """
        bodyA = contact.fixtureA.body
        bodyB = contact.fixtureB.body
        bodyA.userData.preSolve(bodyB, manifold)
        bodyB.userData.preSolve(bodyA, manifold)

    def PostSolve(self, contact: b2Contact, impulse: b2Vec2) -> None:
        """
        Called after Box2D handles a contact while the bodies are no longer overlapping
        """
        bodyA = contact.fixtureA.body
        bodyB = contact.fixtureB.body
        bodyA.userData.postSolve(bodyB, impulse)
        bodyB.userData.postSolve(bodyA, impulse)

Ancestors

  • Box2D.Box2D.b2ContactListener

Methods

def BeginContact(self, contact: Box2D.Box2D.b2Contact) ‑> NoneType

Called when two Box2D bodies collide and calls their beginContact(otherBody) methods contact: The contact event

Expand source code
def BeginContact(self, contact: b2Contact) -> None:
    """
    Called when two Box2D bodies collide and calls their beginContact(otherBody) methods
    ``contact:`` The contact event
    """
    bodyA = contact.fixtureA.body
    bodyB = contact.fixtureB.body
    bodyA.userData.beginContact(bodyB)
    bodyB.userData.beginContact(bodyA)
def EndContact(self, contact: Box2D.Box2D.b2Contact) ‑> NoneType

Called when two Box2D bodies collide and calls their endContact(otherBody) methods contact: The contact event

Expand source code
def EndContact(self, contact: b2Contact) -> None:
    """
    Called when two Box2D bodies collide and calls their endContact(otherBody) methods
    ``contact:`` The contact event
    """
    bodyA = contact.fixtureA.body
    bodyB = contact.fixtureB.body
    bodyA.userData.endContact(bodyB)
    bodyB.userData.endContact(bodyA)
def PostSolve(self, contact: Box2D.Box2D.b2Contact, impulse: Box2D.Box2D.b2Vec2) ‑> NoneType

Called after Box2D handles a contact while the bodies are no longer overlapping

Expand source code
def PostSolve(self, contact: b2Contact, impulse: b2Vec2) -> None:
    """
    Called after Box2D handles a contact while the bodies are no longer overlapping
    """
    bodyA = contact.fixtureA.body
    bodyB = contact.fixtureB.body
    bodyA.userData.postSolve(bodyB, impulse)
    bodyB.userData.postSolve(bodyA, impulse)
def PreSolve(self, contact: Box2D.Box2D.b2Contact, manifold: Box2D.Box2D.b2Manifold) ‑> NoneType

Called before Box2D handles a contact while the bodies are still overlapping

Expand source code
def PreSolve(self, contact: b2Contact, manifold: b2Manifold) -> None:
    """
    Called before Box2D handles a contact while the bodies are still overlapping
    """
    bodyA = contact.fixtureA.body
    bodyB = contact.fixtureB.body
    bodyA.userData.preSolve(bodyB, manifold)
    bodyB.userData.preSolve(bodyA, manifold)