本文整理汇总了Java中com.badlogic.gdx.physics.box2d.Fixture.setUserData方法的典型用法代码示例。如果您正苦于以下问题:Java Fixture.setUserData方法的具体用法?Java Fixture.setUserData怎么用?Java Fixture.setUserData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.physics.box2d.Fixture
的用法示例。
在下文中一共展示了Fixture.setUserData方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createFireBallBody
import com.badlogic.gdx.physics.box2d.Fixture; //导入方法依赖的package包/类
/**
* 创建火球刚体
*/
private Body createFireBallBody(World world) {
BodyDef ballDef = new BodyDef();
Body ballBody;
FixtureDef ballFixDef = new FixtureDef();
Fixture ballFix;
PolygonShape ballShape = new PolygonShape();
//设置形状
ballDef.type = BodyDef.BodyType.KinematicBody;
//position是刚体中心点的位置
if (STATE == State.STATE_RIGHT_FIREBALL) {
ballDef.position.set(mBody.getPosition().x + 0.5f, mBody.getPosition().y);
} else {
ballDef.position.set(mBody.getPosition().x - 0.5f, mBody.getPosition().y);
}
ballBody = world.createBody(ballDef);
ballShape.setAsBox(50 / Constant.RATE, 20 / Constant.RATE);
ballFixDef.shape = ballShape;
ballFixDef.filter.categoryBits = Constant.FIREBALL;
ballFixDef.filter.maskBits = Constant.ENEMY_DAO | Constant.BOSS;
ballFixDef.isSensor = true;
ballFix = ballBody.createFixture(ballFixDef);
ballFix.setUserData("ball");
return ballBody;
}
示例2: AbstractEntity
import com.badlogic.gdx.physics.box2d.Fixture; //导入方法依赖的package包/类
public AbstractEntity(final Box2DService box2d, final int id) {
this.id = id;
this.box2d = box2d;
body = createBody(box2d);
body.setUserData(this);
for (final Fixture fixture : body.getFixtureList()) {
fixture.setUserData(this);
}
}
示例3: createBody
import com.badlogic.gdx.physics.box2d.Fixture; //导入方法依赖的package包/类
public Body createBody(World world, Object userData) {
Body body = world.createBody(bodyDef);
body.setMassData(massData);
body.setUserData(userData);
for (int i = 0; i < fixtureDefs.size; ++i) {
Fixture fixture = body.createFixture(fixtureDefs.get(i));
fixture.setUserData(i);
}
return body;
}
示例4: initPhysics
import com.badlogic.gdx.physics.box2d.Fixture; //导入方法依赖的package包/类
public void initPhysics(int levelID, int entID, float x, float y, int sizeDiameter, short categoryBits, short maskBits, boolean useCCD) {
World world = Game_AI_TestBed.instance().getLevel(levelID).getWorldBox2D();
if (world.isLocked()) {
System.out.println("CANCELLING PHYSICS, WORLD LOCKED");
return;
}
collisionListener = new CollisionListener();
world.setContactListener(collisionListener);
BodyDef def = new BodyDef();
//use static body on terrain objects, but keep sprites as dynamic
def.type = BodyType.DynamicBody;
def.position.set(x, y);
def.bullet = useCCD;
//System.out.println("pos: " + x + " - " + y);
//crashes sometimes, suggestion: [05:15:04] <burakkurkcu> you need to queue your removals and destroy/remove them end of the iteration of box2d
//crash is related to projectile collisions to player, only happens when lots are occuring....
body = world.createBody(def);
/*PolygonShape shape = new PolygonShape();
shape.setAsBox(Cst.SPRITESIZE/2, Cst.SPRITESIZE/2);*/
CircleShape shape = new CircleShape();
shape.setRadius(sizeDiameter/2);
FixtureDef fDef = new FixtureDef();
fDef.shape = shape;
fDef.density = 1F;
fDef.filter.categoryBits = categoryBits;
fDef.filter.maskBits = maskBits;
Fixture fixture = body.createFixture(fDef);
//mainly used for looking up who collided with who
body.setUserData(entID);
fixture.setUserData(entID);
shape.dispose();
}