當前位置: 首頁>>代碼示例>>Java>>正文


Java World.createJoint方法代碼示例

本文整理匯總了Java中com.badlogic.gdx.physics.box2d.World.createJoint方法的典型用法代碼示例。如果您正苦於以下問題:Java World.createJoint方法的具體用法?Java World.createJoint怎麽用?Java World.createJoint使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.badlogic.gdx.physics.box2d.World的用法示例。


在下文中一共展示了World.createJoint方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createBodies

import com.badlogic.gdx.physics.box2d.World; //導入方法依賴的package包/類
@Override public void createBodies(World world) {
    this.anchorBody = Box2DFactory.createCircle(world, this.cx, this.cy, 0.05f, true);
    // Joint angle is 0 when flipper is horizontal.
    // The flipper needs to be slightly extended past anchorBody to rotate correctly.
    float ext = (this.flipperLength > 0) ? -0.05f : +0.05f;
    // Width larger than 0.12 slows rotation?
    this.flipperBody = Box2DFactory.createWall(world, cx+ext, cy-0.12f, cx+flipperLength, cy+0.12f, 0f);
    flipperBody.setType(BodyDef.BodyType.DynamicBody);
    flipperBody.setBullet(true);
    flipperBody.getFixtureList().get(0).setDensity(5.0f);

    jointDef = new RevoluteJointDef();
    jointDef.initialize(anchorBody, flipperBody, new Vector2(this.cx, this.cy));
    jointDef.enableLimit = true;
    jointDef.enableMotor = true;
    // counterclockwise rotations are positive, so flip angles for flippers extending left
    jointDef.lowerAngle = (this.flipperLength>0) ? this.minangle : -this.maxangle;
    jointDef.upperAngle = (this.flipperLength>0) ? this.maxangle : -this.minangle;
    jointDef.maxMotorTorque = 1000f;

    this.joint = (RevoluteJoint)world.createJoint(jointDef);

    flipperBodySet = Collections.singletonList(flipperBody);
    this.setEffectiveMotorSpeed(-this.downspeed); // Force flipper to bottom when field is first created.
}
 
開發者ID:StringMon,項目名稱:homescreenarcade,代碼行數:26,代碼來源:FlipperElement.java

示例2: makePlatform

import com.badlogic.gdx.physics.box2d.World; //導入方法依賴的package包/類
/**
 * Creates a pivoted platform from the given object, at the given world.
 *
 * @param world  The world were the platform will be.
 * @param object The object used to initialize the platform.
 * @return The Platform Model of the created platform.
 */
static PlatformModel makePlatform(World world, RectangleMapObject object) {
    PlatformModel platform = new PlatformModel(world, object);

    Boolean pivoted = object.getProperties().get("pivoted", boolean.class);
    if (pivoted != null && pivoted == true) {
        Rectangle rect = object.getRectangle();
        RectangleMapObject anchorRect = new RectangleMapObject(
                rect.getX() + rect.getWidth() / 2, rect.getY() + rect.getHeight() / 2, 1, 1
        );
        Body anchor = makeRectGround(world, anchorRect);

        RevoluteJointDef jointDef = new RevoluteJointDef();
        jointDef.initialize(anchor, platform.getBody(), platform.getBody().getWorldCenter());
        world.createJoint(jointDef);
    }

    return platform;
}
 
開發者ID:AndreFCruz,項目名稱:feup-lpoo-armadillo,代碼行數:26,代碼來源:B2DFactory.java

示例3: test_deserializeBug

import com.badlogic.gdx.physics.box2d.World; //導入方法依賴的package包/類
public void test_deserializeBug(Vector2 pos){
	/*
	Entity e = factory.build("jeep",pos);
	PhysicsComponent p = mappers.physics.get(e);
	WheelJoint j = (WheelJoint) p.getJoint("leftWheelJoint");
	logger.debug("Factory \n anchorA: " + j.getAnchorA() + "\n anchorB:" + j.getAnchorB() + " \n localAxis: "+ j.getLocalAxisA() + " \n damping: " + j.getSpringDampingRatio() + "\n frequency" + j.getSpringFrequencyHz());

	String data = factory.serialize(e);
	removeEntity(e);
	e = factory.deserialize(data);
	p = mappers.physics.get(e);
	j = (WheelJoint) p.getJoint("leftWheelJoint");
	logger.debug("Deserialized \n anchorA: " + j.getAnchorA() + "\n anchorB:" + j.getAnchorB() + " \n localAxis: "+ j.getLocalAxisA() + " \n damping: " + j.getSpringDampingRatio() + "\n frequency" + j.getSpringFrequencyHz());
	
	addEntity(e);
	*/
	World world = App.engine.systems.physics.world;
	BodyDef bd = new BodyDef();
	bd.type = BodyType.DynamicBody;
	
	Body body = world.createBody(bd),
		 wheel = world.createBody(bd);
	
	PolygonShape rect = new PolygonShape();
	rect.setAsBox(2, 1);
	CircleShape circle = new CircleShape();
	circle.setRadius(1);
	
	body.createFixture(rect,1);
	wheel.createFixture(circle,1);
	
	Vector2 localAnchor = new Vector2(0,0),
			localAxis = new Vector2(0,1);
	
	WheelJointDef jd = new WheelJointDef();
	jd.initialize(body, wheel, localAnchor , localAxis);
	WheelJoint joint = (WheelJoint)world.createJoint(jd);

	System.out.println("Local Axis = " + joint.getLocalAxisA());
	System.out.println("Local Anchor A = " + joint.getLocalAnchorA());
	
	//joint.getLocalAxisA() seems to be returning localAnchorA
	
}
 
開發者ID:Deftwun,項目名稱:ZombieCopter,代碼行數:45,代碼來源:GameEngine.java

示例4: toJoint

import com.badlogic.gdx.physics.box2d.World; //導入方法依賴的package包/類
public Joint toJoint(World world,Body bodyA, Body bodyB){
	logger.debug("Creating Joint");
	JointDef jd = this.toJointDef(bodyA,bodyB);
	return world.createJoint(jd);

	/*
	switch (type){

	case DistanceJoint:{
		return world.createJoint((DistanceJointDef)jd);
	}
	
	case FrictionJoint:{
		return world.createJoint((FrictionJointDef)jd);
	}
	
	case GearJoint:{
		return world.createJoint((GearJointDef)jd);
	}
	
	case MotorJoint:{
		return world.createJoint((MotorJointDef)jd);
	}
	
	case MouseJoint:{
		return world.createJoint((MouseJointDef)jd);
	}
	
	case PrismaticJoint:{
		return world.createJoint((PrismaticJointDef)jd);
	}
	
	case PulleyJoint:{
		return world.createJoint((PulleyJointDef)jd);
	}
	
	case RevoluteJoint:{
		return world.createJoint((RevoluteJointDef)jd);
	}
	
	case RopeJoint:{
		return world.createJoint((RopeJointDef)jd);
	}
	
	case WeldJoint:{
		return world.createJoint((WeldJointDef)jd);
	}
	
	case WheelJoint:{
		return world.createJoint((WheelJointDef)jd);			
	}
	
	}
	return null;
	*/
}
 
開發者ID:Deftwun,項目名稱:ZombieCopter,代碼行數:57,代碼來源:JointModel.java


注:本文中的com.badlogic.gdx.physics.box2d.World.createJoint方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。