本文整理汇总了Java中com.badlogic.gdx.physics.box2d.ChainShape.createLoop方法的典型用法代码示例。如果您正苦于以下问题:Java ChainShape.createLoop方法的具体用法?Java ChainShape.createLoop怎么用?Java ChainShape.createLoop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.physics.box2d.ChainShape
的用法示例。
在下文中一共展示了ChainShape.createLoop方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createBody
import com.badlogic.gdx.physics.box2d.ChainShape; //导入方法依赖的package包/类
@Override
protected Body createBody(final Box2DService box2d) {
final BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.StaticBody;
bodyDef.fixedRotation = true;
final ChainShape shape = new ChainShape();
final float w = Box2DUtil.WIDTH * 2f / 5f, h = Box2DUtil.HEIGHT * 2f / 5f;
shape.createLoop(new float[] { -w, -h, -w, h, w, h, w, -h });
final FixtureDef fixtureDef = new FixtureDef();
fixtureDef.restitution = 0.9f;
fixtureDef.friction = 0.2f;
fixtureDef.shape = shape;
fixtureDef.filter.categoryBits = Box2DUtil.CAT_BOUNDS;
fixtureDef.filter.maskBits = Box2DUtil.MASK_BLOCK;
final Body body = box2d.getWorld().createBody(bodyDef);
body.createFixture(fixtureDef);
return body;
}
示例2: createPhysicsWorld
import com.badlogic.gdx.physics.box2d.ChainShape; //导入方法依赖的package包/类
private void createPhysicsWorld() {
world = new World(new Vector2(0, 0), true);
float halfWidth = viewportWidth / 2f;
ChainShape chainShape = new ChainShape();
chainShape.createLoop(new Vector2[] {
new Vector2(-halfWidth, 0f),
new Vector2(halfWidth, 0f),
new Vector2(halfWidth, viewportHeight),
new Vector2(-halfWidth, viewportHeight) });
BodyDef chainBodyDef = new BodyDef();
chainBodyDef.type = BodyType.StaticBody;
groundBody = world.createBody(chainBodyDef);
groundBody.createFixture(chainShape, 0);
chainShape.dispose();
createBoxes();
}
示例3: createScreenBox
import com.badlogic.gdx.physics.box2d.ChainShape; //导入方法依赖的package包/类
public Body createScreenBox(final Rectangle rect) {
ChainShape shape = new ChainShape();
shape.createLoop(new Vector2[]{
new Vector2(rect.x, rect.y).scl(1 / Box2dObject.RADIO),
new Vector2(rect.x + rect.width, rect.y).scl(1 / Box2dObject.RADIO),
new Vector2(rect.x + rect.width, rect.y + rect.height).scl(1 / Box2dObject.RADIO),
new Vector2(rect.x, rect.y + rect.height).scl(1 / Box2dObject.RADIO),
});
final FixtureDef fixtureDef = new FixtureDef();
fixtureDef.isSensor = false;
fixtureDef.shape = shape;
BodyDef bodyDef = new BodyDef();
bodyDef.bullet = false;
bodyDef.type = BodyType.StaticBody;
bodyDef.linearDamping = 0f;
Body body = PhysicalWorld.WORLD.createBody(bodyDef);
body.createFixture(fixtureDef);
shape.dispose();
return body;
}
示例4: Bounds
import com.badlogic.gdx.physics.box2d.ChainShape; //导入方法依赖的package包/类
public Bounds (World world, float hWidth, float hHeight) {
bodyDef = new BodyDef();
bodyDef.type = BodyType.StaticBody;
body = world.createBody(bodyDef);
ChainShape shape = new ChainShape();
Vector2[] vertices = {new Vector2(-hWidth, -hHeight), new Vector2(-hWidth, hHeight), new Vector2(hWidth, hHeight), new Vector2(hWidth, -hHeight)};
shape.createLoop(vertices);
body.createFixture(shape, 0);
shape.dispose();
body.setUserData("bounds");
}
示例5: randomCircleBody
import com.badlogic.gdx.physics.box2d.ChainShape; //导入方法依赖的package包/类
public static Body randomCircleBody(World world,Vector2 position,float dX,float dY,float minY,float maxY,int randomness){
//TODO: Should use a logger class here
if (360%dX != 0) System.out.println("Creating random planet: dx must be multiple of 360");
assert(360%dX == 0); // must be multiple of 360
int steps = (int) (360 / dX)-1;
Random rand = new Random();
float prevElevation = (minY + maxY) / 2;
boolean randomModeToggle = false;
ArrayList<Vector2> verts = new ArrayList<Vector2>();
for (int x = 1; x < steps; x++){
Vector2 h = new Vector2();
if (randomModeToggle)
h.set(0,rand.nextFloat() * (maxY - minY) + minY);
else
h.set(0,getRandomElevation(prevElevation,dY,minY,maxY));
if (randomness!=0){
if (x%randomness == 0){
randomModeToggle = !randomModeToggle;
}
}
prevElevation = h.y;
h.rotate(x * dX);
verts.add(h);
}
ChainShape shape = new ChainShape();
float[] fVerts = new float[verts.size() * 2];
for (int x=0; x < verts.size(); x++){
fVerts[x*2] = verts.get(x).x;
fVerts[(x*2) + 1] = verts.get(x).y;
}
shape.createLoop(fVerts);
FixtureDef fd = new FixtureDef();
fd.density = 10;
fd.friction = 10;
fd.restitution = 0f;
fd.shape = shape;
BodyDef bd = new BodyDef();
bd.type = BodyDef.BodyType.StaticBody;
bd.position.set(position);
Body body = world.createBody(bd);
body.createFixture(fd);
return body;
}