本文整理匯總了Java中com.badlogic.gdx.physics.box2d.Body.getPosition方法的典型用法代碼示例。如果您正苦於以下問題:Java Body.getPosition方法的具體用法?Java Body.getPosition怎麽用?Java Body.getPosition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.badlogic.gdx.physics.box2d.Body
的用法示例。
在下文中一共展示了Body.getPosition方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: create
import com.badlogic.gdx.physics.box2d.Body; //導入方法依賴的package包/類
/**
* Creates a RotatingGroup by computing the distance and angle to center from the first
* element ID in the ids array.
*/
public static RotatingGroup create(Field field, String[] ids, double cx, double cy, double speed) {
FieldElement element = field.getFieldElementById(ids[0]);
Body body = element.getBodies().get(0);
Vector2 position = body.getPosition();
double radius = Math.hypot(position.x - cx, position.y - cy);
double angle = Math.atan2(position.y - cy, position.x - cx);
return new RotatingGroup(ids, cx, cy, radius, angle, speed);
}
示例2: 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;
}
}
}
}
示例3: FireBall
import com.badlogic.gdx.physics.box2d.Body; //導入方法依賴的package包/類
public FireBall(Body body, int state) {
super(body);
this.STATE = state;
this.startPosition = body.getPosition().x * Constant.RATE;
init();
}