Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8475381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:52:37+00:00 2026-06-10T17:52:37+00:00

I am writing a GameActivity of a swinging pendulum (in AndEngine). While applying CollisionHandler

  • 0

I am writing a GameActivity of a swinging pendulum (in AndEngine).

While applying CollisionHandler, this will produce a series of collision events in the instead of one?? Actually, I’d like it is executed once only when sprites collide.

My case: when the movingBall collides with the mLeftWall, it called 5 times of onCollision(); It was abnormal, I expected only one time.

Should I use ContactListener instead and register with PhysicsWorld? Here’s my Code:

MyGameActivity.java:

/** List of objects to check collision of any animating objects. E.g: walls  */
private ArrayList<IShape> mCollidingTargetList = new ArrayList<IShape>();

/** user-defined collision handler */
PendulumCollisionCallback collideActionCallback = new PendulumCollisionCallback();

@Override
public Scene onCreateScene() 
{
    final Scene scene = super.onCreateScene();

    final VertexBufferObjectManager vertexBufferObjectManager = this.getVertexBufferObjectManager();

    //Create walls
    mWallLeft = new Rectangle(0, 0, 2, mCameraHeight, vertexBufferObjectManager);
    mWallRight = new Rectangle(mCameraWidth - 2, 0, 2, mCameraHeight, vertexBufferObjectManager);
    PhysicsFactory.createBoxBody(mPhyscisWorld, mWallLeft, BodyType.StaticBody, mWallFixtureDef);
    PhysicsFactory.createBoxBody(mPhyscisWorld, mWallRight, BodyType.StaticBody, mWallFixtureDef);
    scene.attachChild(mWallLeft);
    scene.attachChild(mWallRight);

    //Create movingBall - the pendulum ball
    final AnimatedSprite movingBall = new AnimatedSprite(mCenterX, mCenterY, this.mCircleFaceTextureRegion, this.getVertexBufferObjectManager());
    final Body ballBody = PhysicsFactory.createCircleBody(this.mPhysicsWorld, movingBall, BodyType.DynamicBody, mObjectFixtureDef);
    movingBall.setUserData(ballBody); // for getting the body attached with UI

    //..... Stuff to create anchorBody and RevoluteJoint with the movingBall

    //list of bodies where sprites collide
    this.mCollidingTargetList.add(mWallLeft);
    this.mCollidingTargetList.add(mWallRight);

    //Manage user-defined collision handler: movingBall collides with walls
    CollisionHandler pendulumCollideHandler = new CollisionHandler(collideActionCallback, movingBall, mCollidingTargetList);
    scene.registerUpdateHandler(pendulumCollideHandler);

    return scene;
}

PendulumCollisionCallback.java:

public class PendulumCollisionCallback implements ICollisionCallback
{
    public PendulumCollisionCallback()
    { }

    /**
     * @param animatedShape
     *      Entity to check collision with other targets
     * @param pTargetShape
     *      Target to check the collision
     * @return <code>true</code> to proceed, <code>false</code> to stop further collosion-checks.
     */
    @Override
    public boolean onCollision(IShape animatedShape, IShape pTargetShape) 
    {
        String pendulPos = String.format("Pendul:x=%f, y=%f", animatedShape.getX(), animatedShape.getY());      
        Log.d("COLLIDE", pendulPos);
        return false;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:52:39+00:00Added an answer on June 10, 2026 at 5:52 pm

    I found the issue. This is because of separated Physics Handler and Scene’s UpdateHandler work sequence.

    While PhysicsWorld is still controlling body collision, the body is still moving forward for a few frames => so that the position of UI sprite (attached with this body) is in junction with colliding object. During these frames, the updateHandler produces collision events by CallbackHandler.

    The solution is a tricky method of adding Boolean flag which is set at first colliding and unset when finish colliding (though this is not nice).

    P/S: my frame rate observed form FPSLogger is ~88,9 FPS.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Writing a python program, and I came up with this error while using the
Writing some drag&drop code, I'd like to cancel the click events in my mouseup
Writing an app that will include the ability to decompress zip and rar files.
writing in QT and QErrorMessage by default has checkbox saying: Show this message again
Writing Junit Tests for my spring application. Because I am new at this I
Writing a shell script and I want to do something like this: cp myfile.ext
Writing something like this using the loki library , typedef Functor<void> BitButtonPushHandler; throws a
Writing a Reporting Service (2005) report My DataSet returns something like this: DESCRIPTION COUNT
Writing floats to a CSV writes some of them like this: 2.0628800997782577e-05 c =
Writing a function I must declare input and output data types like this: int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.