本文整理了Java中com.badlogic.gdx.physics.box2d.Body.getUserData()
方法的一些代码示例,展示了Body.getUserData()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Body.getUserData()
方法的具体详情如下:
包路径:com.badlogic.gdx.physics.box2d.Body
类名称:Body
方法名:getUserData
[英]Get the user data
[中]获取用户数据
代码示例来源: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: danialgoodwin/dev
public GameActor(Body body) {
this.body = body;
this.userData = (UserData) body.getUserData();
screenRectangle = new Rectangle();
}
代码示例来源:origin: danialgoodwin/dev
public static boolean bodyIsGround(Body body) {
UserData userData = (UserData) body.getUserData();
return userData != null && userData.getUserDataType() == UserDataType.GROUND;
}
代码示例来源:origin: danialgoodwin/dev
public static boolean bodyIsRunner(Body body) {
UserData userData = (UserData) body.getUserData();
return userData != null && userData.getUserDataType() == UserDataType.RUNNER;
}
代码示例来源:origin: danialgoodwin/dev
public static boolean bodyIsEnemy(Body body) {
UserData userData = (UserData) body.getUserData();
return userData != null && userData.getUserDataType() == UserDataType.ENEMY;
}
代码示例来源:origin: narfman0/GDXWorld
protected Body[] getBodyAB(World world){
Body[] bodies = new Body[2];
Array<Body> bodyArray = new Array<>(world.getBodyCount());
world.getBodies(bodyArray);
for(Body body : bodyArray){
if(this.bodyA.equals(body.getUserData()))
bodies[0] = body;
else if(this.bodyB.equals(body.getUserData()))
bodies[1] = body;
}
return bodies;
}
代码示例来源:origin: dsaltares/libgdx-cookbook
@Override
public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {
// Print contact info
Gdx.app.log(TAG, " Contact!! " + fixture.getBody().getUserData() + " at [" + point.x + ";" + point.y + "]");
return -1; // Continue with the rest of the fixtures
}
};
代码示例来源:origin: yichen0831/Bomberman_libGdx
@Override
public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {
if (fixture.getFilterData().categoryBits == GameManager.BOMB_BIT) {
Entity bombEntity = (Entity) fixture.getBody().getUserData();
kickingBomb = bombEntity.getComponent(Bomb.class);
return 0;
}
return 0;
}
};
代码示例来源:origin: danialgoodwin/dev
public static boolean bodyInBounds(Body body) {
UserData userData = (UserData) body.getUserData();
switch (userData.getUserDataType()) {
case RUNNER:
case ENEMY:
return body.getPosition().x + userData.getWidth() / 2 > 0;
}
return true;
}
代码示例来源:origin: danialgoodwin/dev
@Override
public void act(float delta) {
super.act(delta);
if (body.getUserData() != null) {
updateRectangle();
} else {
// This means the world destroyed the body (enemy or runner went out of bounds)
remove();
}
}
代码示例来源:origin: dsaltares/libgdx-cookbook
void freeBalloons() {
Iterator<Body> i = balloons.iterator();
while (i.hasNext()) {
Body balloon = i.next();
boolean broken = (Boolean) balloon.getUserData();
if(((balloon.getPosition().y - BALLOON_HEIGHT*0.5f) > SCENE_HEIGHT) || // Top limit
(balloon.getPosition().y + BALLOON_HEIGHT*0.5f) < 1.0f || // Bottom limit
(balloon.getPosition().x - BALLOON_WIDTH*0.5f) > SCENE_WIDTH || // Right limit
(balloon.getPosition().x + BALLOON_WIDTH*0.5f) < 0 || // Left limit
broken) {
world.destroyBody(balloon);
i.remove();
}
}
}
代码示例来源:origin: narfman0/GDXWorld
world.getBodies(bodyArray);
for(Body body : bodyArray)
if(body.getUserData() instanceof String)
usedBodyNames.put((String)body.getUserData(), body);
HashMap<String, Body> bodies = new HashMap<>();
List<GDXShape> shapes = new ArrayList<>();
代码示例来源:origin: yichen0831/Bomberman_libGdx
@Override
public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {
if (fixture.getFilterData().categoryBits == GameManager.INDESTRUCTIIBLE_BIT) {
canExplodeThrough = false;
return 0;
}
if (fixture.getFilterData().categoryBits == GameManager.BREAKABLE_BIT) {
canExplodeThrough = false;
Entity e = (Entity) fixture.getBody().getUserData();
Breakable breakable = e.getComponent(Breakable.class);
breakable.state = Breakable.State.EXPLODING;
return 0;
}
return 0;
}
};
代码示例来源:origin: dsaltares/libgdx-cookbook
@Override
public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {
collision.set(point);
Box2DQuerySample.this.normal.set(normal).add(point);
// Show contact info
title = fixture.getBody().getUserData() + " at [" + point.x + ";" + point.y + "]";
layout.setText(font, title);
titleWidth = layout.width * 0.5f;
return 1; // Continue with the rest of the fixtures
}
};
代码示例来源:origin: dsaltares/libgdx-cookbook
@Override
public void beginContact(Contact contact) {
// TODO Auto-generated method stub
Fixture fixtureA = contact.getFixtureA();
Fixture fixtureB = contact.getFixtureB();
Body bodyA = fixtureA.getBody();
Body bodyB = fixtureB.getBody();
if (fixtureA.isSensor()) {
Enemy e = (Enemy) bodyA.getUserData();
e.setAngry(true);
//Gdx.app.log(TAG, "T-Rex is angry!!!");
}
else if(fixtureB.isSensor()) {
Enemy e = (Enemy) bodyB.getUserData();
e.setAngry(true);
//Gdx.app.log(TAG, "T-Rex is angry!!!");
}
}
代码示例来源:origin: narfman0/GDXWorld
@Override
public Body getPhysicsObject(String name) {
Array<Body> bodyArray = new Array<>(world.getBodyCount());
world.getBodies(bodyArray);
for (Body body : bodyArray)
if (name != null && name.equals(body.getUserData()))
return body;
return null;
}
代码示例来源:origin: narfman0/GDXWorld
@Override
public boolean isNear(String origin, String target, float distance) {
Body originBody = null, targetBody = null;
Array<Body> bodyArray = new Array<>(world.getBodyCount());
world.getBodies(bodyArray);
for (Body body : bodyArray) {
if (origin != null && origin.equals(body.getUserData()))
originBody = body;
if (target != null && target.equals(body.getUserData()))
targetBody = body;
}
return originBody.getPosition().dst(targetBody.getPosition()) < distance;
}
代码示例来源:origin: yichen0831/Bomberman_libGdx
Entity e = (Entity) fixtureA.getBody().getUserData();
Player player = e.getComponent(Player.class);
player.receivedDamage++;
} else if (fixtureB.getFilterData().categoryBits == GameManager.PLAYER_BIT) {
Entity e = (Entity) fixtureB.getBody().getUserData();
Player player = e.getComponent(Player.class);
player.receivedDamage++;
Entity e = (Entity) fixtureA.getBody().getUserData();
Enemy enemy = e.getComponent(Enemy.class);
enemy.receivedDamage++;
} else if (fixtureB.getFilterData().categoryBits == GameManager.ENEMY_BIT) {
Entity e = (Entity) fixtureB.getBody().getUserData();
Enemy enemy = e.getComponent(Enemy.class);
enemy.receivedDamage++;
Entity e = (Entity) fixtureA.getBody().getUserData();
Bomb bomb = e.getComponent(Bomb.class);
bomb.countDown = 0;
} else if (fixtureB.getFilterData().categoryBits == GameManager.BOMB_BIT) {
Entity e = (Entity) fixtureB.getBody().getUserData();
Bomb bomb = e.getComponent(Bomb.class);
bomb.countDown = 0;
Entity e = (Entity) fixtureA.getBody().getUserData();
Breakable breakable = e.getComponent(Breakable.class);
breakable.state = Breakable.State.EXPLODING;
} else if (fixtureB.getFilterData().categoryBits == GameManager.BREAKABLE_BIT) {
Entity e = (Entity) fixtureB.getBody().getUserData();
代码示例来源:origin: dsaltares/libgdx-cookbook
Enemy e = (Enemy) bodyA.getUserData();
e.setAngry(false);
Enemy e = (Enemy) bodyB.getUserData();
e.setAngry(false);
代码示例来源:origin: manuelbua/uracer-kotd
Object userData = f.getUserData();
if ((body != null) && (userData == CarType.PlayerCar || userData == CarType.ReplayCar)) {
Car car = (Car)body.getUserData();
float[] impulses = impulse.getNormalImpulses();
tmpVec2.set(impulses[0], impulses[1]);
内容来源于网络,如有侵权,请联系作者删除!