/** * Creates a fixture from a shape and attach it to this body. This is a convenience function. Use * FixtureDef if you need to set parameters like friction, restitution, user data, or filtering. * If the density is non-zero, this function automatically updates the mass of the body. * * @param shape the shape to be cloned. * @param density the shape density (set to zero for static bodies). * @warning This function is locked during callbacks. */ public final Fixture createFixture(Shape shape, float density) { fixDef.setShape(shape); fixDef.setDensity(density); return createFixture(fixDef); }
private void createBody(World world, View view) { BodyDef bodyDef = new BodyDef(); bodyDef.setType(BodyType.DYNAMIC); bodyDef.position.set(pixelsToMeters(view.getX() + view.getWidth() / 2) , pixelsToMeters(view.getY() + view.getHeight() / 2)); Shape shape = null; Boolean isCircle = (Boolean) view.getTag(R.id.mobike_view_circle_tag); if(isCircle != null && isCircle){ shape = createCircleShape(view); }else{ shape = createPolygonShape(view); } FixtureDef fixture = new FixtureDef(); fixture.setShape(shape); fixture.friction = friction; fixture.restitution = restitution; fixture.density = density; Body body = world.createBody(bodyDef); body.createFixture(fixture); view.setTag(R.id.mobike_body_tag,body); body.setLinearVelocity(new Vec2(random.nextFloat(),random.nextFloat())); }