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 8352685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:01:55+00:00 2026-06-09T09:01:55+00:00

I’m creating Demo application in which 2 Ball one is moving and one is

  • 0

I’m creating Demo application in which 2 Ball one is moving and one is static (Not moving) . I just want to collide both of them at run time. but my moving object not moving when i apply update position true in this line of code:

this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(ball, body, false, true));

here is my code

public class DizyBall extends SimpleBaseGameActivity implements IOnSceneTouchListener {
// ===========================================================
// Constants
// ===========================================================

private static final int CAMERA_WIDTH = 740;
private static final int CAMERA_HEIGHT = 480;

private static final float DEMO_VELOCITY = 150.0f;

// ===========================================================
// Fields
// ===========================================================
private Scene mScene;
private PhysicsWorld mPhysicsWorld;
private Body body;
private FixtureDef objectFixtureDef ;
private BitmapTextureAtlas mBitmapTextureAtlas;
private TiledTextureRegion mFaceTextureRegion;
private TextureRegion mColiTextureRegion;

// ===========================================================
// Constructors
// ===========================================================

// ===========================================================
// Getter & Setter
// ===========================================================

// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================

@Override
public EngineOptions onCreateEngineOptions() {
    final Camera camera = new Camera(0, 0, DizyBall.CAMERA_WIDTH, DizyBall.CAMERA_HEIGHT);

    return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(DizyBall.CAMERA_WIDTH, DizyBall.CAMERA_HEIGHT), camera);
}

@Override
public void onCreateResources() {
    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");

    this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 48, 48, TextureOptions.BILINEAR);
    this.mFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mBitmapTextureAtlas, this, "ball.png", 0, 0, 1, 1);
    this.mColiTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "ball.png",0,0);

    this.mBitmapTextureAtlas.load();
}

@Override
public Scene onCreateScene() {
    this.mEngine.registerUpdateHandler(new FPSLogger());


    mScene = new Scene();
    mScene.setBackground(new Background(0.09804f, 0.6274f, 0.8784f));
    mScene.setOnSceneTouchListener(this);


    objectFixtureDef = PhysicsFactory.createFixtureDef(1, 0.5f, 0.5f);

    this.mPhysicsWorld = new FixedStepPhysicsWorld(30, new Vector2(0, 0), false, 3, 2);

    final float centerX = (DizyBall.CAMERA_WIDTH - this.mFaceTextureRegion.getWidth()) / 2;
    final float centerY = (DizyBall.CAMERA_HEIGHT - this.mFaceTextureRegion.getHeight()) / 2;

    final Sprite Coli = new Sprite(centerX, centerY, this.mColiTextureRegion, this.getVertexBufferObjectManager());
    body = PhysicsFactory.createCircleBody(this.mPhysicsWorld, Coli, BodyType.DynamicBody, objectFixtureDef);
    this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(Coli, body, true, true));


    mScene.attachChild(Coli);
    this.mScene.registerUpdateHandler(this.mPhysicsWorld);
    return mScene;
}

// ===========================================================
// Methods
// ===========================================================


@Override
public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {

  //        pSceneTouchEvent
    if(this.mPhysicsWorld != null) {
        if(pSceneTouchEvent.isActionUp()){
            final Ball ball = new Ball(pSceneTouchEvent.getX(), pSceneTouchEvent.getY(), this.mFaceTextureRegion, this.getVertexBufferObjectManager());



            body = PhysicsFactory.createCircleBody(this.mPhysicsWorld, ball, BodyType.DynamicBody, objectFixtureDef);

            this.mScene.attachChild(ball);
            this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(ball, body, false, true));
            return false;
        }
    }else{
        Log.v("PhysicsWorld","NULL");
    }

    return false;
}
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================

private static class Ball extends AnimatedSprite {
    private final PhysicsHandler mPhysicsHandler;

    public Ball(final float pX, final float pY, final TiledTextureRegion pTextureRegion, final VertexBufferObjectManager pVertexBufferObjectManager) {
        super(pX, pY, pTextureRegion, pVertexBufferObjectManager);
        this.mPhysicsHandler = new PhysicsHandler(this);
        this.registerUpdateHandler(this.mPhysicsHandler);
        this.mPhysicsHandler.setVelocity(DizyBall.DEMO_VELOCITY, DizyBall.DEMO_VELOCITY);
    }

    @Override
    protected void onManagedUpdate(final float pSecondsElapsed) {
        if(this.mX < 0) {
            this.mPhysicsHandler.setVelocityX(DizyBall.DEMO_VELOCITY);
        } else if(this.mX + this.getWidth() > DizyBall.CAMERA_WIDTH) {
            this.mPhysicsHandler.setVelocityX(-DizyBall.DEMO_VELOCITY);
        }

        if(this.mY < 0) {
            this.mPhysicsHandler.setVelocityY(DizyBall.DEMO_VELOCITY);
        } else if(this.mY + this.getHeight() > DizyBall.CAMERA_HEIGHT) {
            this.mPhysicsHandler.setVelocityY(-DizyBall.DEMO_VELOCITY);
        }

        super.onManagedUpdate(pSecondsElapsed);
    }
}
 }

Bellow is the Image at run time but both are not Collide.
enter image description here

  • 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-09T09:01:57+00:00Added an answer on June 9, 2026 at 9:01 am

    Just add this line after mScene.registerUpdateHandler(this.mPhysicsHandler);

    mScene.registerUpdateHandler(this);
    

    Then implement the updatehandler and add the unimplemented methods, now you can do anything in the onUpdate method, like

    body.setLinearVelocity(10,10);
    

    to make it collide with the other object.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words

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.