-- I'm not referring to Restitution, I see where that is set in >>PhysicsFactory.createFixtureDef- bouncing when the object hits the ground is ok, I'm talking about the random "jittering/bouncing" you see when the object comes to rest on the ground.
What is making this happen??
Using java Syntax Highlighting
- public class TestPhysics extends BaseGameActivity implements IAccelerometerListener { //, IOnSceneTouchListener
- // ===========================================================
- // Constants
- // ===========================================================
- protected static final int CAMERA_WIDTH = 720;
- protected static final int CAMERA_HEIGHT = 480;
- // ===========================================================
- // Fields
- // ===========================================================
- private Texture mTexture;
- protected TextureRegion mBoxTextureRegion;
- protected PhysicsWorld mPhysicsWorld;
- // ===========================================================
- // Methods for/from SuperClass/Interfaces
- // ===========================================================
- @Override
- public Engine onLoadEngine() {
- //Toast.makeText(this, "Touch the screen to add objects.", Toast.LENGTH_LONG).show();
- final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
- return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera));
- }
- @Override
- public void onLoadResources() {
- this.mTexture = new Texture(64, 64, TextureOptions.BILINEAR);
- TextureRegionFactory.setAssetBasePath("gfx/");
- this.mBoxTextureRegion = TextureRegionFactory.createFromAsset(this.mTexture, this, "box.png", 0, 0);
- this.mEngine.getTextureManager().loadTexture(this.mTexture);
- this.enableAccelerometerSensor(this);
- }
- @Override
- public Scene onLoadScene() {
- this.mEngine.registerUpdateHandler(new FPSLogger());
- final Scene scene = new Scene(2);
- scene.setBackground(new ColorBackground(0, 0, 0));
- this.mPhysicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false);
- this.initJoints(scene);
- final Shape ground = new Rectangle(0, CAMERA_HEIGHT - 2, CAMERA_WIDTH, 2);
- final Shape roof = new Rectangle(0, 0, CAMERA_WIDTH, 2);
- final Shape left = new Rectangle(0, 0, 2, CAMERA_HEIGHT);
- final Shape right = new Rectangle(CAMERA_WIDTH - 2, 0, 2, CAMERA_HEIGHT);
- final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f);
- PhysicsFactory.createBoxBody(this.mPhysicsWorld, ground, BodyType.StaticBody, wallFixtureDef);
- PhysicsFactory.createBoxBody(this.mPhysicsWorld, roof, BodyType.StaticBody, wallFixtureDef);
- PhysicsFactory.createBoxBody(this.mPhysicsWorld, left, BodyType.StaticBody, wallFixtureDef);
- PhysicsFactory.createBoxBody(this.mPhysicsWorld, right, BodyType.StaticBody, wallFixtureDef);
- scene.getBottomLayer().addEntity(ground);
- scene.getBottomLayer().addEntity(roof);
- scene.getBottomLayer().addEntity(left);
- scene.getBottomLayer().addEntity(right);
- scene.registerUpdateHandler(this.mPhysicsWorld);
- return scene;
- }
- public void onLoadComplete() {
- }
- @Override
- public void onAccelerometerChanged(final AccelerometerData pAccelerometerData) {
- this.mPhysicsWorld.setGravity(new Vector2(pAccelerometerData.getY(), pAccelerometerData.getX()));
- }
- // ===========================================================
- // Methods
- // ===========================================================
- private void initJoints(final Scene pScene) {
- final int centerX = CAMERA_WIDTH / 2;
- final int centerY = CAMERA_HEIGHT / 2;
- final FixtureDef objectFixtureDef = PhysicsFactory.createFixtureDef(10, 0.2f, 0.5f);
- final Sprite physicsSpriteBox = new Sprite(centerX, centerY, this.mBoxTextureRegion);
- final Body physicsBodyBox = PhysicsFactory.createBoxBody(this.mPhysicsWorld, physicsSpriteBox, BodyType.DynamicBody, objectFixtureDef);
- physicsSpriteBox.setUpdatePhysics(false);
- pScene.getTopLayer().addEntity(physicsSpriteBox);
- this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(physicsSpriteBox, physicsBodyBox, true, true, false, false));
- }
- }
Parsed in 0.044 seconds, using GeSHi 1.0.8.4

