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


Java Body.getUserData方法代码示例

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


在下文中一共展示了Body.getUserData方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: applyForce

import com.badlogic.gdx.physics.box2d.Body; //导入方法依赖的package包/类
/**
    * Apply a force to physics object with a force apply position
    * 
    * @param data
    * @param force
    * @param applyPoint
    */
   protected void applyForce(IPhysicsObject data, Vector2 force,
    Vector2 applyPoint) {
Iterator<Body> bi = world.getBodies();
while (bi.hasNext()) {
    Body b = bi.next();
    IPhysicsObject e;
    try {
	e = (IPhysicsObject) b.getUserData(); // get the IPhysicsObject
    } catch (Exception ex) {
	e = null;
    }
    if (e != null) {
	if (e == data) {
	    if (applyPoint == null)
		b.applyForceToCenter(force);
	    else
		b.applyForce(force, applyPoint);
	}
    }
}
   }
 
开发者ID:game-libgdx-unity,项目名称:GDX-Engine,代码行数:29,代码来源:PhysicsManager.java

示例2: createTempBodyDistanceJoint

import com.badlogic.gdx.physics.box2d.Body; //导入方法依赖的package包/类
public Body createTempBodyDistanceJoint(Body bodyA, Body bodyB,
    Vector2 localA, Vector2 localB, int length) {
DistanceJointDef dJoint = new DistanceJointDef();
FixtureDef fixtureDef = createFixtureDef(1f, 0.5f, 0.2f, (short) 0x0004);
IPhysicsObject sprite = (IPhysicsObject) bodyA.getUserData();
Body temp = createTempBody(sprite.getX(), sprite.getY(), fixtureDef);
createRevoluteJoint(bodyA, temp, localA, Vector2.Zero);
dJoint.bodyA = temp;
dJoint.bodyB = bodyB;
dJoint.localAnchorA.set(localA.x * WORLD_TO_BOX, localA.y
	* WORLD_TO_BOX);
dJoint.localAnchorB.set(localB.x * WORLD_TO_BOX, localB.y
	* WORLD_TO_BOX);
dJoint.length = length * WORLD_TO_BOX;
world.createJoint(dJoint);
return temp;
   }
 
开发者ID:game-libgdx-unity,项目名称:GDX-Engine,代码行数:18,代码来源:PhysicsManager.java

示例3: applyForce

import com.badlogic.gdx.physics.box2d.Body; //导入方法依赖的package包/类
/**
 * Apply a force to physics object with a force apply position
 * 
 * @param data
 * @param force
 * @param applyPoint
 */
protected void applyForce(IPhysicsObject data, Vector2 force,
		Vector2 applyPoint) {
	Iterator<Body> bi = world.getBodies();
	while (bi.hasNext()) {
		Body b = bi.next();
		IPhysicsObject e;
		try {
			e = (IPhysicsObject) b.getUserData(); // get the IPhysicsObject
		} catch (Exception ex) {
			e = null;
		}
		if (e != null) {
			if (e == data) {
				if (applyPoint == null)
					b.applyForceToCenter(force);
				else
					b.applyForce(force, applyPoint);
			}
		}
	}
}
 
开发者ID:game-libgdx-unity,项目名称:GDX-Engine,代码行数:29,代码来源:PhysicsTiledScene.java

示例4: createTempBodyDistanceJoint

import com.badlogic.gdx.physics.box2d.Body; //导入方法依赖的package包/类
public Body createTempBodyDistanceJoint(Body bodyA, Body bodyB,
		Vector2 localA, Vector2 localB, int length) {
	DistanceJointDef dJoint = new DistanceJointDef();
	FixtureDef fixtureDef = createFixtureDef(1f, 0.5f, 0.2f, (short) 0x0004);
	IPhysicsObject sprite = (IPhysicsObject) bodyA.getUserData();
	Body temp = createTempBody(sprite.getX(), sprite.getY(), fixtureDef);
	createRevoluteJoint(bodyA, temp, localA, Vector2.Zero);
	dJoint.bodyA = temp;
	dJoint.bodyB = bodyB;
	dJoint.localAnchorA.set(localA.x * WORLD_TO_BOX, localA.y
			* WORLD_TO_BOX);
	dJoint.localAnchorB.set(localB.x * WORLD_TO_BOX, localB.y
			* WORLD_TO_BOX);
	dJoint.length = length * WORLD_TO_BOX;
	world.createJoint(dJoint);
	return temp;
}
 
开发者ID:game-libgdx-unity,项目名称:GDX-Engine,代码行数:18,代码来源:PhysicsTiledScene.java

示例5: update

import com.badlogic.gdx.physics.box2d.Body; //导入方法依赖的package包/类
@Override
   public void update(float gameTime) {
// implement the world physics
world.step(BOX_STEP, BOX_VELOCITY_ITERATIONS, BOX_POSITION_ITERATIONS);
world.clearForces();

Iterator<Body> bi = world.getBodies();
while (bi.hasNext()) {
    Body b = bi.next();

    if (b == null)
	continue;

    if (b.getUserData() instanceof IPhysicsObject) {
	IPhysicsObject e = (IPhysicsObject) b.getUserData();
	// get the x, y position
	float x = b.getPosition().x * BOX_TO_WORLD - e.getRegionWidth()
		/ 2;
	float y = b.getPosition().y * BOX_TO_WORLD
		- e.getRegionHeight() / 2;
	// set position and rotation of sprite based the body in world
	// physics
	e.setX(x);
	e.setY(y);
	e.setRotation(MathUtils.radiansToDegrees * b.getAngle());
	e.update(gameTime);
    } else if (b.getUserData() instanceof String) {
	String str = (String) b.getUserData();
	if ("remove".equals(str)) {
	    b.setUserData(null);
	    world.destroyBody(b);
	    b = null;
	}
    }
}
   }
 
开发者ID:game-libgdx-unity,项目名称:GDX-Engine,代码行数:37,代码来源:PhysicsManager.java


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