当前位置: 首页>>代码示例>>Java>>正文


Java MouseJointDef类代码示例

本文整理汇总了Java中com.badlogic.gdx.physics.box2d.joints.MouseJointDef的典型用法代码示例。如果您正苦于以下问题:Java MouseJointDef类的具体用法?Java MouseJointDef怎么用?Java MouseJointDef使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MouseJointDef类属于com.badlogic.gdx.physics.box2d.joints包,在下文中一共展示了MouseJointDef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addedToEngine

import com.badlogic.gdx.physics.box2d.joints.MouseJointDef; //导入依赖的package包/类
@Override
public void addedToEngine(Engine engine) {
    super.addedToEngine(engine);
    this.camera = context.get(Camera.class);
    this.physics = context.get(World.class);
    if (Settings.DRAGGABLE_BOX2D_BODIES) {
        jointDef = new MouseJointDef();
        jointDef.bodyA = context.get(LBBuilders.class).getBodyBuilder().build();
        jointDef.collideConnected = true;
        jointDef.maxForce = Settings.DRAGGABLE_BOX2D_MAX_FORCE;

    } else {
        Log.error(tag, "A reference not set up a draggableRefBody");

    }

}
 
开发者ID:Rubentxu,项目名称:GDX-Logic-Bricks,代码行数:18,代码来源:DraggableBodySystem.java

示例2: JointSerializer

import com.badlogic.gdx.physics.box2d.joints.MouseJointDef; //导入依赖的package包/类
public JointSerializer(RubeScene scene,Json _json)
{
	this.scene = scene;
	_json.setSerializer(RevoluteJointDef.class, 	new RevoluteJointDefSerializer());
	_json.setSerializer(PrismaticJointDef.class, 	new PrismaticJointDefSerializer());
	_json.setSerializer(PulleyJointDef.class, 		new PulleyJointDefSerializer());
	_json.setSerializer(WeldJointDef.class, 		new WeldJointDefSerializer());
	_json.setSerializer(FrictionJointDef.class, 	new FrictionJointDefSerializer());
	_json.setSerializer(WheelJointDef.class, 		new WheelJointDefSerializer());
	_json.setSerializer(RopeJointDef.class, 		new RopeJointDefSerializer());
	_json.setSerializer(DistanceJointDef.class, 	new DistanceJointDefSerializer());
	_json.setSerializer(GearJointDef.class, 		new GearJointDefSerializer());
	
	mouseJointDefSerializer = new MouseJointDefSerializer();
	
	_json.setSerializer(MouseJointDef.class, 		mouseJointDefSerializer);
}
 
开发者ID:tescott,项目名称:RubeLoader,代码行数:18,代码来源:JointSerializer.java

示例3: read

import com.badlogic.gdx.physics.box2d.joints.MouseJointDef; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public MouseJointDef read(Json json, JsonValue jsonData, Class type)
{	
	MouseJointDef defaults = RubeDefaults.Joint.mouseDef;
	
	MouseJointDef def = new MouseJointDef();

	// Don't forget to set the target to the joint once it's created
	target = json.readValue("target", Vector2.class, defaults.target, jsonData);
	
	Vector2 anchorB = json.readValue("anchorB", Vector2.class, defaults.target, jsonData);
	
	if(target != null && anchorB != null)
	{
		def.target.set(anchorB);
		def.maxForce 		= json.readValue("maxForce", 		float.class, 	defaults.maxForce, 		jsonData);
		def.frequencyHz 	= json.readValue("frequency", 		float.class, 	defaults.frequencyHz, 	jsonData);
		def.dampingRatio 	= json.readValue("dampingRatio", 	float.class, 	defaults.dampingRatio, 	jsonData);
	}
	
	return def; 
}
 
开发者ID:tescott,项目名称:RubeLoader,代码行数:24,代码来源:JointSerializer.java

示例4: createMouseJoint

import com.badlogic.gdx.physics.box2d.joints.MouseJointDef; //导入依赖的package包/类
/**
 * Create mouse joint with ground body, target body and location on target body
 * @param groundBody
 * @param targetBody
 * @param locationWorld
 * @return
 */
public MouseJoint createMouseJoint(Body groundBody, Body targetBody, Vector2 locationWorld){
	MouseJointDef md = new MouseJointDef();
       md.bodyA = groundBody;
       md.bodyB = targetBody;
       md.target.set(locationWorld.x, locationWorld.y);
       md.collideConnected = true;
       md.maxForce = 10000.0f * targetBody.getMass();
       
       MouseJoint _mouseJoint = (MouseJoint)world.createJoint(md);
       targetBody.setAwake(true);
       
       return _mouseJoint;
}
 
开发者ID:game-libgdx-unity,项目名称:GDX-Engine,代码行数:21,代码来源:PhysicsTiledScene.java

示例5: touchDown

import com.badlogic.gdx.physics.box2d.joints.MouseJointDef; //导入依赖的package包/类
@Override
public boolean touchDown (int x, int y, int pointer, int button) {
	// translate the mouse coordinates to world coordinates
	camera.unproject(testPoint.set(x, y, 0));
	// ask the world which bodies are within the given
	// bounding box around the mouse pointer
	hitBody = null;
	world.QueryAABB(callback, testPoint.x - 0.0001f, testPoint.y - 0.0001f, testPoint.x + 0.0001f, testPoint.y + 0.0001f);

	if (hitBody == groundBody) hitBody = null;

	// ignore kinematic bodies, they don't work with the mouse joint
	if (hitBody != null && hitBody.getType() == BodyType.KinematicBody) return false;

	// if we hit something we create a new mouse joint
	// and attach it to the hit body.
	if (hitBody != null) {
		MouseJointDef def = new MouseJointDef();
		def.bodyA = groundBody;
		def.bodyB = hitBody;
		def.collideConnected = true;
		def.target.set(testPoint.x, testPoint.y);
		def.maxForce = 1000.0f * hitBody.getMass();

		mouseJoint = (MouseJoint)world.createJoint(def);
		hitBody.setAwake(true);
	}

	return false;
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:31,代码来源:Box2DTest.java

示例6: touchDown

import com.badlogic.gdx.physics.box2d.joints.MouseJointDef; //导入依赖的package包/类
@Override
public boolean touchDown (int x, int y, int pointer, int newParam) {
	// translate the mouse coordinates to world coordinates
	testPoint.set(x, y, 0);
	camera.unproject(testPoint);

	// ask the world which bodies are within the given
	// bounding box around the mouse pointer
	hitBody = null;
	world.QueryAABB(callback, testPoint.x - 0.1f, testPoint.y - 0.1f, testPoint.x + 0.1f, testPoint.y + 0.1f);

	// if we hit something we create a new mouse joint
	// and attach it to the hit body.
	if (hitBody != null) {
		MouseJointDef def = new MouseJointDef();
		def.bodyA = groundBody;
		def.bodyB = hitBody;
		def.collideConnected = true;
		def.target.set(testPoint.x, testPoint.y);
		def.maxForce = 1000.0f * hitBody.getMass();

		mouseJoint = (MouseJoint)world.createJoint(def);
		hitBody.setAwake(true);
	} else {
		for (Body box : boxes)
			world.destroyBody(box);
		boxes.clear();
		createBoxes();
	}

	return false;
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:33,代码来源:Box2DTest.java

示例7: createMouseJointDefinition

import com.badlogic.gdx.physics.box2d.joints.MouseJointDef; //导入依赖的package包/类
/**
 * Creates the MouseJoint definition.
 * 
 * @param body
 *            First body of the joint (i.e. ground, walls, etc.)
 */
private void createMouseJointDefinition(Body body) {
	mouseJointDef = new MouseJointDef();
	mouseJointDef.bodyA = body;
	mouseJointDef.collideConnected = true;
	mouseJointDef.maxForce = 500;
}
 
开发者ID:Leakedbits,项目名称:Codelabs,代码行数:13,代码来源:DragAndDropSample.java

示例8: touchDown

import com.badlogic.gdx.physics.box2d.joints.MouseJointDef; //导入依赖的package包/类
@Override
public boolean touchDown(int x, int y, int pointer, int newParam) {
	// translate the mouse coordinates to world coordinates
	testPoint.set(x, y, 0);
	camera.unproject(testPoint);

	// ask the world which bodies are within the given
	// bounding box around the mouse pointer
	hitBody = null;
	world.QueryAABB(callback, testPoint.x - 0.1f, testPoint.y - 0.1f,
			testPoint.x + 0.1f, testPoint.y + 0.1f);

	// if we hit something we create a new mouse joint
	// and attach it to the hit body.
	if (hitBody != null) {
		MouseJointDef def = new MouseJointDef();
		def.bodyA = groundBody;
		def.bodyB = hitBody;
		def.collideConnected = true;
		def.target.set(testPoint.x, testPoint.y);
		def.maxForce = 1000.0f * hitBody.getMass();

		mouseJoint = (MouseJoint) world.createJoint(def);
		hitBody.setAwake(true);
	}

	return false;
}
 
开发者ID:libgdx,项目名称:box2dlights,代码行数:29,代码来源:Box2dLightCustomShaderTest.java

示例9: touchDown

import com.badlogic.gdx.physics.box2d.joints.MouseJointDef; //导入依赖的package包/类
@Override
public boolean touchDown (int x, int y, int pointer, int newParam) {
	if(world == null)return false;
	// translate the mouse coordinates to world coordinates
	testPoint.set(Engine.screenToWorld(x, y).scl(1/Box2dObject.RADIO));

	// ask the world which bodies are within the given
	// bounding box around the mouse pointer
	hitBody = null;
	world.QueryAABB(callback, testPoint.x - 0.1f, testPoint.y - 0.1f, testPoint.x + 0.1f, testPoint.y + 0.1f);

	// if we hit something we create a new mouse joint
	// and attach it to the hit body.
	if (hitBody != null) {
		MouseJointDef def = new MouseJointDef();
		def.bodyA = fixBody;
		def.bodyB = hitBody;
		def.collideConnected = true;
		def.target.set(testPoint.x, testPoint.y);
		def.maxForce = 1000.0f * hitBody.getMass();

		mouseJoint = (MouseJoint)world.createJoint(def);
		hitBody.setAwake(true);
		
		return true;
	} 

	return false;
}
 
开发者ID:lycying,项目名称:c2d-engine,代码行数:30,代码来源:MouseJointInput.java

示例10: createMouseJoint

import com.badlogic.gdx.physics.box2d.joints.MouseJointDef; //导入依赖的package包/类
/**
 * Sacado del ejemplo de AE demostrando MouseJoint.
 * 
 * Esta función crea  un {@link MouseJoint}.
 * 
 * @param entidad
 *            the entidad
 * @param pTouchAreaLocalX
 *            the touch area local x
 * @param pTouchAreaLocalY
 *            the touch area local y
 * @return the mouse joint
 */
private MouseJoint createMouseJoint(final IEntity entidad,
		final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
	final Body body = ((ObjetoFisico<?>) entidad.getUserData()).getCuerpo();
	final MouseJointDef mouseJointDef = new MouseJointDef();

	final float[] coordsEscena = entidad
			.convertLocalCoordinatesToSceneCoordinates(pTouchAreaLocalX,
					pTouchAreaLocalY);
	final Vector2 localPoint = Vector2Pool.obtain(
			(coordsEscena[0] - (entidad.getWidth() * entidad
					.getOffsetCenterX()))
					/ PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT,
			(coordsEscena[1] - (entidad.getHeight() * entidad
					.getOffsetCenterY()))
					/ PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT);

	/*
	 * realmente el MouseJoint solo usa un cuerpo(el bodyB) pero es
	 * obligatorio suministrarle otro por lo que tradicionalmente se usa el
	 * del suelo ( que suele estar siempre presente)
	 */
	mouseJointDef.bodyA = suelo;
	mouseJointDef.bodyB = body;
	mouseJointDef.dampingRatio = 0.00f;
	mouseJointDef.frequencyHz = 10f;
	mouseJointDef.maxForce = (100 * body.getMass() * 4);
	mouseJointDef.collideConnected = true; //si desactivamos la colision las piezas ignorarán el suelo :-)

	mouseJointDef.target.set(localPoint);
	Vector2Pool.recycle(localPoint);

	return (MouseJoint) mundo.createJoint(mouseJointDef);
}
 
开发者ID:sprayz,项目名称:Phytris,代码行数:47,代码来源:EscenaJuego.java

示例11: B2FlxMouseJoint

import com.badlogic.gdx.physics.box2d.joints.MouseJointDef; //导入依赖的package包/类
/**
 * Constructor
 */
public B2FlxMouseJoint()
{
	_mouseJointDef = new MouseJointDef();
	_groundBody = B2FlxB.world.createBody(new BodyDef());
	_testPoint = new Vector2();
	_mouseTarget = new Vector2();
	_removeBySchedule = false;
}
 
开发者ID:flixel-gdx,项目名称:flixel-gdx-box2d,代码行数:12,代码来源:B2FlxMouseJoint.java

示例12: setupMouseJoint

import com.badlogic.gdx.physics.box2d.joints.MouseJointDef; //导入依赖的package包/类
public void setupMouseJoint(World world, BodyDef bd) {
    BodyDef groundBodyDef = new BodyDef();
    groundBodyDef.position.set(0, 0);
    mMouseJointBody = world.createBody(groundBodyDef);
    // create a mousejoint
    MouseJointDef mouseJointDef = new MouseJointDef();
    mouseJointDef.bodyA = mMouseJointBody;
    mouseJointDef.bodyB = mBody;
    mouseJointDef.dampingRatio = 0.2f;
    mouseJointDef.frequencyHz = 30;
    mouseJointDef.maxForce = 20000.0f;
    mouseJointDef.collideConnected = true;
    mouseJointDef.target.set(bd.position);
    mMouseJoint = (MouseJoint) world.createJoint(mouseJointDef);
}
 
开发者ID:tschut,项目名称:drturbo,代码行数:16,代码来源:SpaceObject.java

示例13: show

import com.badlogic.gdx.physics.box2d.joints.MouseJointDef; //导入依赖的package包/类
@Override
public void show() {
    // Stage
    stage = new ExtendedStage(this, new WisperChooseMenu());
    initInputListener();
    Gdx.input.setInputProcessor(stage);
    Gdx.input.setCatchBackKey(true);

    // Box2d
    world = new World(new Vector2(0, -9.81f), true); // newton -9.81f
    debugRenderer = new Box2DDebugRenderer();
    initContactListener();

    // Wisper & Batch
    timer = new Timer();
    batch = new SpriteBatch();
    wisper = new WisperBox2d(chosenWisper, world);

    // Temps
    new WisperBox2d(Wisper.BLACK_WISPER, world).setPosition(
            Config.APP_WIDTH / 2 - 10,
            Config.APP_HEIGHT / 2 - 10);

    new WisperBox2d(Wisper.BLUE_WISPER, world).setPosition(
            Config.APP_WIDTH / 2 + 10,
            Config.APP_HEIGHT / 2 + 10);

    // Tiled map
    TiledMap map = new TmxMapLoader().load("tiledmap/tiledmap.tmx");
    mapRenderer = new OrthogonalTiledMapRenderer(map, Config.GAME_RATIO);
    box2dParser = new Box2DMapObjectParser(Config.GAME_RATIO);
    box2dParser.load(world, map);

    // Joint
    jointDef = new MouseJointDef();
    jointDef.bodyA = box2dParser.getBodies().values().next();
    jointDef.collideConnected = true;
    jointDef.bodyB = wisper.getBody();
}
 
开发者ID:Drusy,项目名称:Wisper,代码行数:40,代码来源:GameScreen.java

示例14: touchDown

import com.badlogic.gdx.physics.box2d.joints.MouseJointDef; //导入依赖的package包/类
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    if (slingshotEnabled == false)
        return false;

    /* Translate the mouse coordinates to world coordinates */
    stage.getCamera().unproject(testPoint.set(screenX, screenY, 0));
    testPoint.x *= G.WORLD_TO_BOX;
    testPoint.y *= G.WORLD_TO_BOX;

    hitBody = null;
    body.getWorld().QueryAABB(callback,
                    testPoint.x - 0.0001f,
                    testPoint.y - 0.0001f,
                    testPoint.x + 0.0001f,
                    testPoint.y + 0.0001f);
    if (hitBody == groundBody) hitBody = null;

    if (hitBody == null)
        return false;

    /* Ignore kinematic bodies, they don't work with the mouse joint */
    if (hitBody.getType() == BodyType.KinematicBody)
        return false;

    if (hitBody.equals(this.body)) {
        MouseJointDef def = new MouseJointDef();
        def.bodyA = groundBody;
        def.bodyB = hitBody;
        def.collideConnected = true;
        def.target.set(testPoint.x, testPoint.y);
        def.maxForce = a_max * hitBody.getMass();

        startPoint.set(testPoint.x, testPoint.y);
        mouseJoint = (MouseJoint)((body.getWorld()).createJoint(def));
        hitBody.setAwake(true);
    }
    return false;
}
 
开发者ID:OlliV,项目名称:angr,代码行数:40,代码来源:SlingshotActor.java

示例15: create

import com.badlogic.gdx.physics.box2d.joints.MouseJointDef; //导入依赖的package包/类
@Override
public void create() {
	// C�mara del juego
	camera = new OrthographicCamera();
	// Zona visible de la c�mara
	camera.viewportWidth = 480;
	camera.viewportHeight = 320;
	// Colca la c�mara en el centro de la pantalla
	camera.position.set(camera.viewportWidth / 2, camera.viewportHeight / 2, 0f);
	camera.update();
	
	spriteBatch = new SpriteBatch();
	font = new BitmapFont();
	
	world = new World(new Vector2(0, -10f), true);
	renderer = new Box2DDebugRenderer();
	
	// Define un cuerpo (la tierra)
	BodyDef groundDef = new BodyDef();
	groundDef.type = BodyType.StaticBody;
	groundDef.position.set(new Vector2(0, 10));
	Body groundBody= world.createBody(groundDef);

	PolygonShape groundShape = new PolygonShape();
	groundShape.setAsBox(camera.viewportWidth * 2, 10.0f);
	groundBody.createFixture(groundShape, 0.0f);
	
	// A�ade un coche al mundo con una velocidad inicial
	car = WorldGenerator.createCar(world, 280, 60);
	car.setLinearVelocity(new Vector2(10f, 0));
	
	Body circle = WorldGenerator.createCircleBody(world, 200, 200);
	
	// A�ade una rampa
	Body floor = WorldGenerator.createPolygonBody(world, 250, 70, 100, -50);
	
	mouseJointDef = new MouseJointDef();
	mouseJointDef.bodyA = groundBody;
	mouseJointDef.collideConnected = true;
	mouseJointDef.maxForce = 500000;
	
	Gdx.input.setInputProcessor(this);
}
 
开发者ID:sfaci,项目名称:libgdx,代码行数:44,代码来源:MyWorld.java


注:本文中的com.badlogic.gdx.physics.box2d.joints.MouseJointDef类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。