本文整理汇总了Java中com.badlogic.gdx.physics.box2d.CircleShape类的典型用法代码示例。如果您正苦于以下问题:Java CircleShape类的具体用法?Java CircleShape怎么用?Java CircleShape使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CircleShape类属于com.badlogic.gdx.physics.box2d包,在下文中一共展示了CircleShape类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createCircle
import com.badlogic.gdx.physics.box2d.CircleShape; //导入依赖的package包/类
/** Creates a circle object with the given position and radius. Resitution defaults to 0.6. */
public static Body createCircle(World world, float x, float y, float radius, boolean isStatic) {
CircleShape sd = new CircleShape();
sd.setRadius(radius);
FixtureDef fdef = new FixtureDef();
fdef.shape = sd;
fdef.density = 1.0f;
fdef.friction = 0.3f;
fdef.restitution = 0.6f;
BodyDef bd = new BodyDef();
bd.allowSleep = true;
bd.position.set(x, y);
Body body = world.createBody(bd);
body.createFixture(fdef);
if (isStatic) {
body.setType(BodyDef.BodyType.StaticBody);
}
else {
body.setType(BodyDef.BodyType.DynamicBody);
}
return body;
}
示例2: createStaticCircleBody
import com.badlogic.gdx.physics.box2d.CircleShape; //导入依赖的package包/类
/**
* Create static body from a TiledObject Refer the box2d manual to
* understand the static body
*
* @param o
* TiledObject
*/
public Body createStaticCircleBody(float x, float y, float radius) {
BodyDef groundBodyDef = new BodyDef();
groundBodyDef.type = BodyType.StaticBody;
// transform into box2d
x = x * WORLD_TO_BOX;
// get position-y of object from map
y = Gdx.graphics.getHeight() - y;
// transform into box2d
y = y * WORLD_TO_BOX;
groundBodyDef.position.set(x, y);
Body groundBody = world.createBody(groundBodyDef);
CircleShape shape = new CircleShape();
((CircleShape) shape).setRadius(radius * WORLD_TO_BOX / 2);
groundBody.createFixture(shape, 0.0f);
groundBody.setUserData("static");
return groundBody;
}
示例3: createTempBody
import com.badlogic.gdx.physics.box2d.CircleShape; //导入依赖的package包/类
public Body createTempBody(float x, float y, FixtureDef fixtureDef) {
// Dynamic Body
BodyDef bodyDef = new BodyDef();
if (box2dDebug)
bodyDef.type = BodyType.StaticBody;
else
bodyDef.type = BodyType.DynamicBody;
// transform into box2d
x = x * WORLD_TO_BOX;
y = y * WORLD_TO_BOX;
bodyDef.position.set(x, y);
Body body = world.createBody(bodyDef);
Shape shape = new CircleShape();
((CircleShape) shape).setRadius(1 * WORLD_TO_BOX);
if (fixtureDef == null)
throw new GdxRuntimeException("fixtureDef cannot be null!");
fixtureDef.shape = shape;
body.createFixture(fixtureDef);
return body;
}
示例4: createRopeTipBody
import com.badlogic.gdx.physics.box2d.CircleShape; //导入依赖的package包/类
private Body createRopeTipBody()
{
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DynamicBody;
bodyDef.linearDamping = 0.5f;
Body body = world.createBody(bodyDef);
FixtureDef circleDef = new FixtureDef();
CircleShape circle = new CircleShape();
circle.setRadius(1.0f/PTM_RATIO);
circleDef.shape = circle;
circleDef.density = 10.0f;
// Since these tips don't have to collide with anything
// set the mask bits to zero
circleDef.filter.maskBits = 0x01; //0;
body.createFixture(circleDef);
return body;
}
示例5: createStaticCircleBody
import com.badlogic.gdx.physics.box2d.CircleShape; //导入依赖的package包/类
/**
* Create static body from a TiledObject Refer the box2d manual to
* understand the static body
*
* @param o
* TiledObject
*/
public Body createStaticCircleBody(float x, float y, float radius) {
BodyDef groundBodyDef = new BodyDef();
groundBodyDef.type = BodyType.StaticBody;
// transform into box2d
x = x * WORLD_TO_BOX;
// get position-y of object from map
y = tileMapRenderer.getMapHeightUnits() - y;
// transform into box2d
y = y * WORLD_TO_BOX;
groundBodyDef.position.set(x, y);
Body groundBody = world.createBody(groundBodyDef);
CircleShape shape = new CircleShape();
((CircleShape) shape).setRadius(radius * WORLD_TO_BOX / 2);
groundBody.createFixture(shape, 0.0f);
groundBody.setUserData("static");
return groundBody;
}
示例6: createTempBody
import com.badlogic.gdx.physics.box2d.CircleShape; //导入依赖的package包/类
public Body createTempBody(float x, float y, FixtureDef fixtureDef) {
// Dynamic Body
BodyDef bodyDef = new BodyDef();
if (box2dDebug)
bodyDef.type = BodyType.StaticBody;
else
bodyDef.type = BodyType.DynamicBody;
// transform into box2d
x = x * WORLD_TO_BOX;
y = y * WORLD_TO_BOX;
bodyDef.position.set(x, y);
Body body = world.createBody(bodyDef);
Shape shape = new CircleShape();
((CircleShape) shape).setRadius(1 * WORLD_TO_BOX);
if (fixtureDef == null)
throw new GdxRuntimeException("fixtureDef cannot be null!");
fixtureDef.shape = shape;
body.createFixture(fixtureDef);
return body;
}
示例7: createSpinner
import com.badlogic.gdx.physics.box2d.CircleShape; //导入依赖的package包/类
public static Body createSpinner(World world) {
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyDef.BodyType.DynamicBody;
bodyDef.position.set(Constants.SPINNER_POSITIONS);
Body body = world.createBody(bodyDef);
CircleShape circle = new CircleShape();
circle.setRadius(Constants.SPINNER_SIZE);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = circle;
fixtureDef.density = Constants.SPENNER_DENSITY;
fixtureDef.friction = 0f;
fixtureDef.restitution = 0.45f;
body.createFixture(fixtureDef);
circle.dispose();
return body;
}
示例8: createStaticAttackBody
import com.badlogic.gdx.physics.box2d.CircleShape; //导入依赖的package包/类
/**
* Erzeugt automatisch einen Kreis als statischen Trigger.
*
* @see AttackHandler#createAttackFixture(Body, Shape)
*
* @param position der Mittelpunkt des Kreises
* @param radius der Radius des Kreises
*/
public void createStaticAttackBody(Vector2 position, float radius)
{
CircleShape circle = new CircleShape();
circle.setPosition(new Vector2(position.x, position.y).scl(Physics.MPP));
circle.setRadius(radius * Physics.MPP);
BodyDef triggerDef = new BodyDef();
triggerDef.type = BodyDef.BodyType.StaticBody;
Body trigger = manager.getPhysicalWorld().createBody(triggerDef);
createAttackFixture(trigger, circle);
circle.dispose();
}
示例9: initBall
import com.badlogic.gdx.physics.box2d.CircleShape; //导入依赖的package包/类
private void initBall() {
float radius = 26;
mBall = new Circle(0.f, 0.f, radius);
mBallTextureRegion = new TextureRegion(new Texture(Gdx.files.internal("ball.png")));
// create physics body
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyDef.BodyType.DynamicBody;
bodyDef.position.set(mBall.x, mBall.y);
CircleShape ballShape = new CircleShape();
ballShape.setRadius(mBall.radius - 2.f);
mBallBody = mWorld.createBody(bodyDef);
mBallBody.setUserData(new BodyUserDate(BODY_USER_DATA_TYPE_BALL));
Fixture fixture = mBallBody.createFixture(ballShape, 0.5f);
fixture.setFriction(BALL_FRICTION_BASE);
fixture.setRestitution(0.4f);
ballShape.dispose();
}
示例10: definePlayer
import com.badlogic.gdx.physics.box2d.CircleShape; //导入依赖的package包/类
public void definePlayer(){
BodyDef bdef = new BodyDef();
bdef.position.set(100 / QuackHack.PPM, 1500 / QuackHack.PPM); // Mario start position
bdef.type = BodyDef.BodyType.DynamicBody;
b2body = world.createBody(bdef);
FixtureDef fdef = new FixtureDef();
CircleShape shape = new CircleShape();
shape.setRadius(64 / QuackHack.PPM);
fdef.filter.categoryBits = QuackHack.MARIO_BIT;
fdef.filter.maskBits = QuackHack.DEFAULT_BIT;
fdef.friction = 0;
fdef.density = 0.1f;
fdef.shape = shape;
b2body.createFixture(fdef);
b2body.createFixture(fdef).setUserData(this);
}
示例11: Food
import com.badlogic.gdx.physics.box2d.CircleShape; //导入依赖的package包/类
public Food(World world, float x, float y, int size, float toGive) {
super(x, y);
color = new Color((float) Math.random(), (float) Math.random(), (float) Math.random(), 1);
outline = Advio.instance.darker(color);
BodyDef bd = new BodyDef();
bd.type = BodyType.KinematicBody;
bd.position.set(x, y);
CircleShape shape = new CircleShape();
shape.setRadius(size);
FixtureDef fd = new FixtureDef();
fd.density = 0.1f;
fd.shape = shape;
fd.friction = 0.1f;
// fd.filter.groupIndex = Advio.GROUP_BEINGS;
body = world.createBody(bd);
body.createFixture(fd).setUserData(new UserData("food").add("toGive", toGive));
shape.dispose();
}
示例12: Player
import com.badlogic.gdx.physics.box2d.CircleShape; //导入依赖的package包/类
public Player(World world, float x, float y) {
super(x, y);
this.world = world;
this.graphicsSize = 10;
color = new Color((float) Math.random(), (float) Math.random(), (float) Math.random(), 1);
outline = Advio.instance.darker(color);
BodyDef bd = new BodyDef();
bd.type = BodyType.DynamicBody;
bd.position.set(x, y);
CircleShape shape = new CircleShape();
shape.setRadius(50);
FixtureDef fd = new FixtureDef();
fd.density = 0.0f;
fd.shape = shape;
fd.friction = 0.1f;
body = world.createBody(bd);
body.createFixture(fd).setUserData(new UserData("player"));
shape.dispose();
// size * 2.25f
}
示例13: Enemy
import com.badlogic.gdx.physics.box2d.CircleShape; //导入依赖的package包/类
public Enemy(World world, float x, float y, int size) {
super(x, y);
this.world = world;
this.graphicsSize = 0.1f;
color = new Color((float) Math.random(), (float) Math.random(), (float) Math.random(), 1);
outline = Advio.instance.darker(color);
BodyDef bd = new BodyDef();
bd.type = BodyType.DynamicBody;
bd.position.set(x, y);
CircleShape shape = new CircleShape();
shape.setRadius(size);
FixtureDef fd = new FixtureDef();
fd.density = 0.0f;
fd.shape = shape;
fd.friction = 0.1f;
body = world.createBody(bd);
body.createFixture(fd).setUserData(new UserData("enemy").add("body", body));
shape.dispose();
}
示例14: apply
import com.badlogic.gdx.physics.box2d.CircleShape; //导入依赖的package包/类
@Override
public void apply () {
Body body = ((Rigidbody)getParent().getComponentByType(ComponentType.Rigidbody)).getBody();
FixtureDef fixtureDef = new FixtureDef();
CircleShape shape = new CircleShape();
shape.setPosition(new Vector2(x, y));
shape.setRadius(radius);
fixtureDef.density = density;
fixtureDef.friction = friction;
fixtureDef.isSensor = isSensor;
fixtureDef.restitution = restitution;
fixtureDef.shape = shape;
if (fixture != null) {
dispose();
fixture = null;
((Rigidbody)getParent().getComponentByType(ComponentType.Rigidbody)).apply();
rebuildAll();
getParent().transform.setRotation(getParent().transform.getRotation());
return;
}
fixture = body.createFixture(fixtureDef);
fixture.setFilterData(filter);
UserData userdata = new UserData();
userdata.component = (Rigidbody)getParent().getComponentByName("Rigidbody");
fixture.setUserData(userdata);
}
示例15: Player
import com.badlogic.gdx.physics.box2d.CircleShape; //导入依赖的package包/类
public Player (TextureRegion texture, float x, float y) {
this.texture = texture;
BodyDef ballD = new BodyDef();
ballD.position.set(x, y);
ballD.type = BodyType.DynamicBody;
body = world.createBody(ballD);
FixtureDef ballFD = new FixtureDef();
ballShape = new CircleShape();
ballShape.setRadius(BALL_WIDTH / 2);
ballFD.shape = ballShape;
ballFD.density = 1;
ballFD.friction = 0;
ballFD.restitution = 1;
ballFD.filter.categoryBits = CATEGORY_PLAYER;
ballFD.filter.maskBits = MASK_PLAYER;
body.createFixture(ballFD);
ballShape.dispose();
}