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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:10:56+00:00 2026-06-10T14:10:56+00:00

I have a problem with physics in AndEngine. My sprite shakes while moving and

  • 0

I have a problem with physics in AndEngine. My sprite shakes while moving and sometimes jumps. I made my ‘floor’ of boxes 32×32 and everyone is another body, so I thought this is the issue (some collision with their corners or something). I’ve tried to use one shape instead of those boxes, but the problem remains.

It looks like the surfece of my floor is not straight but somehow irregular…

My question is, how to make my character move smoothly on this surface?

And by the way, how to make my character heavier?

My whole code is here:

private final int CAMERA_WIDTH = 800;
private final int CAMERA_HEIGHT = 480;

enum PlayerAction {
    RUN,
    NONE,
    JUMP
}

enum Direction {
    RIGHT,
    LEFT,
    NONE
}

enum BodyId {
    PLAYER,
    BOX
}

Direction mPlayerDirection = Direction.NONE;
Direction mLastPlayerDirection = Direction.NONE;

private Camera mCamera;
private Scene mGameScene;

private PhysicsWorld mPhysicsWorld;

private BitmapTextureAtlas mBoxBitmapTextureAtlas;
private BitmapTextureAtlas mPlayerBitmapTextureAtlas;
private ITextureRegion mBoxTextureRegion;
private TiledTextureRegion mPlayerTextureRegion;

private AnimatedSprite mPlayer;
private Body mPlayerBody;

private BitmapTextureAtlas mOnScreenControlTexture;
private ITextureRegion mOnScreenControlBaseTextureRegion;
private ITextureRegion mOnScreenControlKnobTextureRegion;

private AnalogOnScreenControl mAnalogOnScreenControl;

@Override
public EngineOptions onCreateEngineOptions() {

    this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
    EngineOptions mEngineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new FillResolutionPolicy(), this.mCamera);
    mEngineOptions.getTouchOptions().setNeedsMultiTouch(true);

    return mEngineOptions;
}
@Override
public void onCreateResources(
        OnCreateResourcesCallback pOnCreateResourcesCallback)
        throws Exception {

    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
    this.mBoxBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 32, 32, TextureOptions.BILINEAR);
    this.mBoxTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBoxBitmapTextureAtlas, this, "box.png", 0, 0);
    this.mBoxBitmapTextureAtlas.load();

    this.mPlayerBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 256, 128, TextureOptions.BILINEAR);
    this.mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mPlayerBitmapTextureAtlas, this, "player.png", 0, 0, 3, 4);
    this.mPlayerBitmapTextureAtlas.load();

    this.mOnScreenControlTexture = new BitmapTextureAtlas(this.getTextureManager(), 256, 128, TextureOptions.BILINEAR);
    this.mOnScreenControlBaseTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mOnScreenControlTexture, this, "onscreen_control_base.png", 0, 0);
    this.mOnScreenControlKnobTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mOnScreenControlTexture, this, "onscreen_control_knob.png", 128, 0);
    this.mOnScreenControlTexture.load();

    pOnCreateResourcesCallback.onCreateResourcesFinished();
}
@Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback)
        throws Exception {

    this.mGameScene = new Scene();

    initPhysics(this.mGameScene);

    for(int i = 0; i <= 50; i++) {
        Sprite sprite = new Sprite(i*32, this.mCamera.getHeight() - this.mBoxTextureRegion.getHeight(), this.mBoxTextureRegion, this.getVertexBufferObjectManager());
        createBody(sprite, BodyType.StaticBody, 1, 0, 0, BodyId.BOX);
        this.mGameScene.attachChild(sprite);
    }

    /* Calculate the coordinates for the face, so its centered on the camera. */
    final float playerX = (CAMERA_WIDTH - this.mPlayerTextureRegion.getWidth()) / 2;
    final float playerY = CAMERA_HEIGHT - this.mPlayerTextureRegion.getHeight() - 128;

    this.mPlayer = new AnimatedSprite(playerX, playerY, this.mPlayerTextureRegion, this.getVertexBufferObjectManager()) {

        @Override
        protected void onManagedUpdate(float pSecondsElapsed) {
            super.onManagedUpdate(pSecondsElapsed);
            switch (mPlayerDirection) {
            case RIGHT:
                if (!mPlayerDirection.equals(mLastPlayerDirection)) {
                    mLastPlayerDirection = Direction.RIGHT;
                    GameActivity.this.mPlayer.animate(new long[]{200, 200, 200}, 3, 5, true);
                }
                break;
            case LEFT:
                if (!mPlayerDirection.equals(mLastPlayerDirection)) {
                    mLastPlayerDirection = Direction.LEFT;
                    GameActivity.this.mPlayer.animate(new long[]{200, 200, 200}, 9, 11, true);
                }
                break;
            case NONE:
                mLastPlayerDirection = Direction.NONE;
                GameActivity.this.mPlayer.setCurrentTileIndex(6);
                GameActivity.this.mPlayer.stopAnimation();
                break;
            default:
                mLastPlayerDirection = Direction.NONE;
                GameActivity.this.mPlayer.setCurrentTileIndex(6);
                GameActivity.this.mPlayer.stopAnimation();
                break;
            }
        }
    };

    this.mPlayer.setScaleCenterY(this.mPlayerTextureRegion.getHeight());
    this.mPlayer.setScale(2);
    this.mGameScene.attachChild(this.mPlayer);

    this.mCamera.setChaseEntity(mPlayer);

    this.mPlayerBody = createMovingBody(this.mPlayer, BodyType.DynamicBody, 1, 0, 0, BodyId.PLAYER);

    this.mAnalogOnScreenControl = new AnalogOnScreenControl(32, CAMERA_HEIGHT - this.mOnScreenControlBaseTextureRegion.getHeight() - 32, this.mCamera, this.mOnScreenControlBaseTextureRegion, this.mOnScreenControlKnobTextureRegion, 0.1f, 200, this.getVertexBufferObjectManager(), new IAnalogOnScreenControlListener() {
        @Override
        public void onControlChange(final BaseOnScreenControl pBaseOnScreenControl, final float pValueX, final float pValueY) {

            GameActivity.this.mPlayerBody.setLinearVelocity(new Vector2(pValueX*10, GameActivity.this.mPlayerBody.getLinearVelocity().y));

            if (pValueX > 0)
                GameActivity.this.mPlayerDirection = Direction.RIGHT;
            else if (pValueX < 0)
                GameActivity.this.mPlayerDirection = Direction.LEFT;
            else
                GameActivity.this.mPlayerDirection = Direction.NONE;
        }

        @Override
        public void onControlClick(
                AnalogOnScreenControl pAnalogOnScreenControl) {
            GameActivity.this.mPlayerBody.setLinearVelocity(new Vector2(GameActivity.this.mPlayerBody.getLinearVelocity().x, -8.0f));
        }
    });

    this.mAnalogOnScreenControl.getControlBase().setBlendFunction(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
    this.mAnalogOnScreenControl.getControlBase().setAlpha(0.2f);
    this.mAnalogOnScreenControl.getControlBase().setScaleCenter(0, 128);
    this.mAnalogOnScreenControl.getControlBase().setScale(1.25f);
    this.mAnalogOnScreenControl.getControlKnob().setScale(1.25f);
    this.mAnalogOnScreenControl.refreshControlKnobPosition();

    this.mGameScene.setChildScene(this.mAnalogOnScreenControl);

    pOnCreateSceneCallback.onCreateSceneFinished(this.mGameScene);
}
@Override
public void onPopulateScene(Scene pScene,
        OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {

    this.mEngine.registerUpdateHandler(new TimerHandler(3f, true, new ITimerCallback() {
        @Override
        public void onTimePassed(TimerHandler pTimerHandler) {
            // TODO Auto-generated method stub

        }

    }));

    pOnPopulateSceneCallback.onPopulateSceneFinished();
}

private void initPhysics(Scene pScene)
{
    mPhysicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false);
    pScene.registerUpdateHandler(mPhysicsWorld);
}

private Body createBody(Sprite pSprite, BodyType pBodyType, float pDensity, float pElasticity, float pFriction, BodyId pBodyId)
{
    final FixtureDef objectFixtureDef = PhysicsFactory.createFixtureDef(pDensity, pElasticity, pFriction);
    Body body = PhysicsFactory.createBoxBody(this.mPhysicsWorld, pSprite, pBodyType, objectFixtureDef);
    body.setUserData(pBodyId);
    return body;
}

private Body createMovingBody(Sprite pSprite, BodyType pBodyType, float pDensity, float pElasticity, float pFriction, BodyId pBodyId) {
    Body body = createBody(pSprite, pBodyType, pDensity, pElasticity, pFriction, pBodyId);
    mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(pSprite, body, true, false));
    return body;
}
  • 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-10T14:10:58+00:00Added an answer on June 10, 2026 at 2:10 pm

    I believe this could be caused by insufficient CPU speed. When the processor can’t keep up with the demands of Box2D, the simulation suffers. The bodies can fall a little bit into the space occupied by floor and are pushed upwards in the next simulation cycle. This also happens when some background application causes the CPU load to spike.

    Try running the application on a faster phone or one without other applications running in background. I solved similar problem using the great MaxStepPhysicsWorld, which can be found here: http://www.andengine.org/forums/features/max-step-physics-to-avoid-choppyness-and-bad-simulation-t1271.html

    The way it works is, when the engine is unable to perform enough simulation steps per second, MaxStepPhysicsWorld gives up on being real-time and rather performs enough simulation steps per “second” thus ensuring good simulation.

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

Sidebar

Related Questions

I have problem while loading data into html select when users press or click
I have a classic physics-thread vs. graphics-thread problem: Say I'm running one thread for
I'm developing a physics game using AndEngine with box2d physics engine. I have a
I have got some problem implementing bullet physics into my opengl game. The thing
I'm developing an impulse based physics engine, but I have a problem with objects
I have a problem with a game I am making. I am using physics
I have problem with http://abfoodpolicy.com/ . In IE 8 and 9 the right sidebar
I have problem with my query on C, I’m using the oci8 driver. This
I have problem with repopulating form_upload after validation. Other input fields or selectboxes are
I have problem with show or hide form in Window Form Application. I start

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.