本文整理了Java中com.badlogic.gdx.physics.box2d.Body.getPosition()
方法的一些代码示例,展示了Body.getPosition()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Body.getPosition()
方法的具体详情如下:
包路径:com.badlogic.gdx.physics.box2d.Body
类名称:Body
方法名:getPosition
[英]Get the world body origin position.
[中]获取世界实体原点位置。
代码示例来源:origin: libgdx/libgdx
@Override
public boolean shouldCollide (Fixture fixtureA, Fixture fixtureB) {
if ((fixtureA == m_platform && fixtureB == m_character) || (fixtureB == m_platform && fixtureA == m_character)) {
Vector2 position = m_character.getBody().getPosition();
if (position.y < m_top + m_radius - 3.0f * 0.005f)
return false;
else
return true;
} else
return true;
}
代码示例来源:origin: libgdx/libgdx
/** Initialize the bodies and offsets using the current transforms. */
public void initialize (Body body1, Body body2) {
this.bodyA = body1;
this.bodyB = body2;
this.linearOffset.set(bodyA.getLocalPoint(bodyB.getPosition()));
this.angularOffset = bodyB.getAngle() - bodyA.getAngle();
}
代码示例来源:origin: libgdx/libgdx
/** Initialize the bodies and offsets using the current transforms. */
public void initialize (Body body1, Body body2) {
this.bodyA = body1;
this.bodyB = body2;
this.linearOffset.set(bodyA.getLocalPoint(bodyB.getPosition()));
this.angularOffset = bodyB.getAngle() - bodyA.getAngle();
}
代码示例来源:origin: libgdx/libgdx
protected void renderBody (Body body) {
Transform transform = body.getTransform();
for (Fixture fixture : body.getFixtureList()) {
if (drawBodies) {
drawShape(fixture, transform, getColorByBody(body));
if (drawVelocities) {
Vector2 position = body.getPosition();
drawSegment(position, body.getLinearVelocity().add(position), VELOCITY_COLOR);
}
}
if (drawAABBs) {
drawAABB(fixture, transform);
}
}
}
代码示例来源:origin: libgdx/libgdx
private boolean isPlayerGrounded (float deltaTime) {
groundedPlatform = null;
Array<Contact> contactList = world.getContactList();
for (int i = 0; i < contactList.size; i++) {
Contact contact = contactList.get(i);
if (contact.isTouching()
&& (contact.getFixtureA() == playerSensorFixture || contact.getFixtureB() == playerSensorFixture)) {
Vector2 pos = player.getPosition();
WorldManifold manifold = contact.getWorldManifold();
boolean below = true;
for (int j = 0; j < manifold.getNumberOfContactPoints(); j++) {
below &= (manifold.getPoints()[j].y < pos.y - 1.5f);
}
if (below) {
if (contact.getFixtureA().getUserData() != null && contact.getFixtureA().getUserData().equals("p")) {
groundedPlatform = (Platform)contact.getFixtureA().getBody().getUserData();
}
if (contact.getFixtureB().getUserData() != null && contact.getFixtureB().getUserData().equals("p")) {
groundedPlatform = (Platform)contact.getFixtureB().getBody().getUserData();
}
return true;
}
return false;
}
}
return false;
}
代码示例来源:origin: libgdx/libgdx
@Override
public void render () {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
cam.position.set(player.getPosition().x, player.getPosition().y, 0);
cam.update();
renderer.render(world, cam.combined);
Vector2 pos = player.getPosition();
boolean grounded = isPlayerGrounded(Gdx.graphics.getDeltaTime());
if (grounded) {
代码示例来源:origin: libgdx/libgdx
for (int i = 0; i < boxes.size(); i++) {
Body box = boxes.get(i);
Vector2 position = box.getPosition(); // that's the box's center position
float angle = MathUtils.radiansToDegrees * box.getAngle(); // the rotation angle around the center
batch.draw(textureRegion, position.x - 1, position.y - 1, // the bottom left corner of the box, unrotated
代码示例来源:origin: dsaltares/libgdx-cookbook
public void draw(SpriteBatch batch) {
batch.draw(
texture,
playerBody.getPosition().x - (PLAYER_WIDTH * .5f), playerBody.getPosition().y - (PLAYER_HEIGHT * .5f),
PLAYER_WIDTH, PLAYER_HEIGHT);
}
代码示例来源:origin: dozingcat/Vector-Pinball
@Override public void draw(IFieldRenderer renderer) {
float px = bumperBody.getPosition().x;
float py = bumperBody.getPosition().y;
renderer.fillCircle(px, py, radius, currentColor(DEFAULT_COLOR));
}
}
代码示例来源:origin: BrentAureli/SuperMario
public TiledMapTileLayer.Cell getCell(){
TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(1);
return layer.getCell((int)(body.getPosition().x * MarioBros.PPM / 16),
(int)(body.getPosition().y * MarioBros.PPM / 16));
}
代码示例来源:origin: dozingcat/Vector-Pinball
Vector2 impulseForBall(Ball ball) {
if (this.kick <= 0.01f) return null;
// Compute unit vector from center of bumper to ball, and scale by kick value to get impulse.
Vector2 ballpos = ball.getPosition();
Vector2 thisPos = bumperBody.getPosition();
float ix = ballpos.x - thisPos.x;
float iy = ballpos.y - thisPos.y;
float mag = (float)Math.hypot(ix, iy);
float scale = this.kick / mag;
return new Vector2(ix*scale, iy*scale);
}
代码示例来源:origin: manuelbua/uracer-kotd
@Override
public void saveStateTo (EntityRenderState state) {
state.position.set(body.getPosition());
state.orientation = body.getAngle();
}
代码示例来源:origin: manuelbua/uracer-kotd
@Override
public void setWorldPosMt (Vector2 worldPosition, float orientationRads) {
super.setWorldPosMt(worldPosition, orientationRads);
previousPosition.set(body.getPosition());
}
代码示例来源:origin: BrentAureli/SuperMario
@Override
public void update(float dt) {
setRegion(getFrame(dt));
if(currentState == State.STANDING_SHELL && stateTime > 5){
currentState = State.WALKING;
velocity.x = 1;
System.out.println("WAKE UP SHELL");
}
setPosition(b2body.getPosition().x - getWidth() / 2, b2body.getPosition().y - 8 /MarioBros.PPM);
b2body.setLinearVelocity(velocity);
}
代码示例来源:origin: dozingcat/Vector-Pinball
RotatingGroup createRotatingGroup(Field field, String centerID, String[] ids, double speed) {
FieldElement centerElement = field.getFieldElementById(centerID);
Vector2 centerPosition = centerElement.getBodies().get(0).getPosition();
return RotatingGroup.create(field, ids, centerPosition.x, centerPosition.y, speed);
}
代码示例来源:origin: BrentAureli/SuperMario
@Override
public void update(float dt) {
super.update(dt);
setPosition(body.getPosition().x - getWidth() / 2, body.getPosition().y - getHeight() / 2);
velocity.y = body.getLinearVelocity().y;
body.setLinearVelocity(velocity);
}
}
代码示例来源:origin: com.badlogicgames.gdx/gdx-box2d
/** Initialize the bodies and offsets using the current transforms. */
public void initialize (Body body1, Body body2) {
this.bodyA = body1;
this.bodyB = body2;
this.linearOffset.set(bodyA.getLocalPoint(bodyB.getPosition()));
this.angularOffset = bodyB.getAngle() - bodyA.getAngle();
}
代码示例来源:origin: com.badlogicgames.box2dlights/box2dlights
protected void updateBody() {
if (body == null || staticLight) return;
final Vector2 vec = body.getPosition();
float angle = body.getAngle();
final float cos = MathUtils.cos(angle);
final float sin = MathUtils.sin(angle);
final float dX = bodyOffsetX * cos - bodyOffsetY * sin;
final float dY = bodyOffsetX * sin + bodyOffsetY * cos;
start.x = vec.x + dX;
start.y = vec.y + dY;
setDirection(bodyAngleOffset + angle * MathUtils.radiansToDegrees);
}
代码示例来源:origin: dozingcat/Vector-Pinball
public void draw(IFieldRenderer renderer) {
CircleShape shape = (CircleShape)body.getFixtureList().get(0).getShape();
Vector2 center = body.getPosition();
float radius = shape.getRadius();
renderer.fillCircle(center.x, center.y, radius, primaryColor);
// Draw a smaller circle to show the ball's rotation.
float angle = body.getAngle();
float smallCenterX = center.x + (radius / 2) * MathUtils.cos(angle);
float smallCenterY = center.y + (radius / 2) * MathUtils.sin(angle);
renderer.fillCircle(smallCenterX, smallCenterY, radius / 4, secondaryColor);
}
代码示例来源:origin: dsaltares/libgdx-cookbook
@Override
public boolean touchDown (int x, int y, int pointer, int button) {
// Screen coordinates to world coordinates
viewport.getCamera().unproject(point.set(x, y, 0));
if (button == Input.Buttons.LEFT) {
float force = 100f * player1.getBody().getMass();
Vector2 target = new Vector2(point.x, point.y);
Vector2 direction = target.sub(player1.getBody().getPosition());
player1.getBody().applyForceToCenter(direction.scl(force), true);
}
return false;
}
内容来源于网络,如有侵权,请联系作者删除!