Example usage for com.badlogic.gdx.physics.box2d Contact isEnabled

List of usage examples for com.badlogic.gdx.physics.box2d Contact isEnabled

Introduction

In this page you can find the example usage for com.badlogic.gdx.physics.box2d Contact isEnabled.

Prototype

public boolean isEnabled() 

Source Link

Document

Has this contact been disabled?

Usage

From source file:edu.lehigh.cse.lol.Obstacle.java

License:Open Source License

/**
 * Make the object a callback object, so that custom code will run when a
 * /hero/ collides with it/*  ww w.j  av a 2  s. c o m*/
 *
 * @param activationGoodies1 Number of type-1 goodies that must be collected before this
 *                           callback works
 * @param activationGoodies2 Number of type-2 goodies that must be collected before this
 *                           callback works
 * @param activationGoodies3 Number of type-3 goodies that must be collected before this
 *                           callback works
 * @param activationGoodies4 Number of type-4 goodies that must be collected before this
 *                           callback works
 * @param delay              The time between when the collision happens, and when the
 *                           callback code runs. Use 0 for immediately
 * @param callback           The code to run when the collision happens
 */
public void setHeroCollisionCallback(int activationGoodies1, int activationGoodies2, int activationGoodies3,
        int activationGoodies4, final float delay, final LolCallback callback) {
    // save the required goodie counts, turn off collisions
    final int[] counts = new int[] { activationGoodies1, activationGoodies2, activationGoodies3,
            activationGoodies4 };
    setCollisionsEnabled(false);

    // register a callback
    mHeroCollision = new CollisionCallback() {
        @Override
        public void go(final Actor ps, Contact c) {
            // Make sure the contact is active (it's not if this is a
            // pass-through event)
            if (c.isEnabled()) {
                // check if callback is activated, if so run Callback code
                boolean match = true;
                for (int i = 0; i < 4; ++i)
                    match &= counts[i] <= Lol.sGame.mCurrentLevel.mScore.mGoodiesCollected[i];
                if (match) {
                    // run now, or delay?
                    if (delay <= 0) {
                        callback.mAttachedActor = Obstacle.this;
                        callback.mCollideActor = ps;
                        callback.onEvent();
                    } else {
                        Timer.schedule(new Task() {
                            @Override
                            public void run() {
                                callback.mAttachedActor = Obstacle.this;
                                callback.mCollideActor = ps;
                                callback.onEvent();
                            }
                        }, delay);
                    }
                }
            }
        }
    };
}