本文整理汇总了Java中com.badlogic.gdx.physics.box2d.BodyDef.BodyType类的典型用法代码示例。如果您正苦于以下问题:Java BodyType类的具体用法?Java BodyType怎么用?Java BodyType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BodyType类属于com.badlogic.gdx.physics.box2d.BodyDef包,在下文中一共展示了BodyType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createStaticBoxBody
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; //导入依赖的package包/类
/**
* Create static body from a TiledObject Refer the box2d manual to
* understand the static body
*
* @param o
* TiledObject
*/
public Body createStaticBoxBody(float x, float y, float width, float height) {
BodyDef groundBodyDef = new BodyDef();
groundBodyDef.type = BodyType.StaticBody;
// transform into box2d
x = x * WORLD_TO_BOX;
// get position-y 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);
PolygonShape polygon = new PolygonShape();
((PolygonShape) polygon).setAsBox(width * WORLD_TO_BOX / 2, height
* WORLD_TO_BOX / 2);
groundBody.createFixture(polygon, 0.0f);
groundBody.setUserData("static");
return groundBody;
}
示例2: createStaticCircleBody
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; //导入依赖的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.BodyDef.BodyType; //导入依赖的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.BodyDef.BodyType; //导入依赖的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: createStaticBoxBody
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; //导入依赖的package包/类
/**
* Create static body from a TiledObject Refer the box2d manual to
* understand the static body
*
* @param o
* TiledObject
*/
public Body createStaticBoxBody(float x, float y, float width, float height) {
BodyDef groundBodyDef = new BodyDef();
groundBodyDef.type = BodyType.StaticBody;
// transform into box2d
x = x * WORLD_TO_BOX;
// get position-y from map
y = tileMapRenderer.getMapHeightUnits() - y;
// transform into box2d
y = y * WORLD_TO_BOX;
groundBodyDef.position.set(x, y);
Body groundBody = world.createBody(groundBodyDef);
PolygonShape polygon = new PolygonShape();
((PolygonShape) polygon).setAsBox(width * WORLD_TO_BOX / 2, height
* WORLD_TO_BOX / 2);
groundBody.createFixture(polygon, 0.0f);
groundBody.setUserData("static");
return groundBody;
}
示例6: createStaticCircleBody
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; //导入依赖的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;
}
示例7: createTempBody
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; //导入依赖的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;
}
示例8: createBody
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; //导入依赖的package包/类
private void createBody() {
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DynamicBody;
// Set our body's starting position in the world
bodyDef.position.set(Gdx.input.getX() / 100f, camera.viewportHeight - Gdx.input.getY() / 100f);
// Create our body in the world using our body definition
Body body = world.createBody(bodyDef);
// Create a circle shape and set its radius to 6
PolygonShape square = new PolygonShape();
square.setAsBox(0.3f, 0.3f);
// Create a fixture definition to apply our shape to
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = square;
fixtureDef.density = 0.5f;
fixtureDef.friction = 0.5f;
fixtureDef.restitution = 0.5f;
// Create our fixture and attach it to the body
body.createFixture(fixtureDef);
square.dispose();
}
示例9: SpotlightCop
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; //导入依赖的package包/类
public SpotlightCop(CGCWorld theWorld, Animation newLowAnimation,
Animation newMidAnimation, Animation newHighAnimation,
EntityType pEntityType, Body attachedBody, short pID,
float cameraPosX, float cameraPosY)
{
super(theWorld, newLowAnimation, newMidAnimation, newHighAnimation, pEntityType, attachedBody, pID);
body.getFixtureList().get(0).setSensor(true);
// Create spotlight
Body b = CGCWorld.getBF().createCircle(cameraPosX, cameraPosY,
2.1f, BodyType.DynamicBody, BodyFactory.CAT_INTERACTABLE, BodyFactory.MASK_INTERACTABLE);
b.getFixtureList().get(0).setSensor(true);
b.setFixedRotation(true);
spotlight = new Spotlight(null, null, TextureAnimationDrawer.spotlightAnim,
EntityType.TARGETER, b, CGCWorld.getCamera(), getPID());
b.setUserData(spotlight);
spotlight.addToWorldLayers(CGCWorld.getLH());
alive = true;
lowState = AnimationState.STAND;
}
示例10: fire
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; //导入依赖的package包/类
private void fire()
{
if (target != null) // If null, the targeter is missing somehow
{
// Create a bullet to fire
Body b = CGCWorld.getBF().createCircle(body.getWorldCenter().x,
body.getWorldCenter().y,
0.1f, BodyType.DynamicBody, BodyFactory.CAT_INTERACTABLE, BodyFactory.MASK_INTERACTABLE);
GameEntity ge = new RiderBullet(null, null, com.percipient24.cgc.art.TextureAnimationDrawer.bulletAnim, EntityType.BULLET,
b, target.getBody().getPosition(),
new Vector2(target.getHighRegion().getRegionWidth() / 2,
target.getHighRegion().getRegionHeight() / 2), false);
b.setUserData(ge);
ge.addToWorldLayers(CGCWorld.getLH());
}
}
示例11: SteelHorse
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; //导入依赖的package包/类
public SteelHorse(Animation newLowAnimation, Animation newMidAnimation,
Animation newHighAnimation, EntityType pEntityType, Body attachedBody)
{
super(newLowAnimation, newMidAnimation, newHighAnimation, pEntityType, attachedBody);
setTimers();
hp = MAX_HP;
offset = (float) ((Math.random() - 0.5f) * accuracy);
target = CGCWorld.getPrisoners().random();
Vector2 sheriffPos = body.getWorldCenter().cpy().sub(new Vector2(0, getImageHalfHeight(0) / 2).rotate(rotation));
Body b = CGCWorld.getBF().createCircle(0, 0,
0.6f, BodyType.StaticBody, BodyFactory.CAT_IMPASSABLE, BodyFactory.MASK_SHERIFF_GROUND);
sheriff = new Sheriff(com.percipient24.cgc.art.TextureAnimationDrawer.sheriffAnim, com.percipient24.cgc.art.TextureAnimationDrawer.sheriffAnim, com.percipient24.cgc.art.TextureAnimationDrawer.sheriffAnim, EntityType.SHERIFF, b, this);
sheriff.addToWorldLayers(CGCWorld.getLH());
//sheriff.addTargeter();
b.setUserData(sheriff);
b.setTransform(sheriffPos, 0);
}
示例12: addTargeter
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; //导入依赖的package包/类
public void addTargeter()
{
if(targeter == null)
{
Body bod = CGCWorld.getBF().createCircle(body.getWorldCenter().cpy().x,
body.getWorldCenter().cpy().y, 0.5f, BodyType.DynamicBody,
BodyFactory.CAT_NON_INTERACTIVE, BodyFactory.MASK_NON_INTERACTIVE);
bod.getFixtureList().get(0).setSensor(true);
bod.setFixedRotation(true);
targeter = new Targeter(null, null, com.percipient24.cgc.art.TextureAnimationDrawer.targetingAnims[0], EntityType.TARGETER, bod, CGCWorld.getCamera(), -1);
bod.setUserData(targeter);
targeter.addToWorldLayers(CGCWorld.getLH());
TimerManager.addTimer(fireTimer);
}
}
示例13: createBoss
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; //导入依赖的package包/类
public Boss createBoss()
{
Boss boss;
Body bossBody = CGCWorld.getBF().createRectangle(9.5f, 0, 20f, 0.5f, BodyType.DynamicBody,
BodyFactory.CAT_BOSS, BodyFactory.MASK_BOSS);
if (aiControl)
{
boss = new Tank(TextureAnimationDrawer.tankAnims[0], TextureAnimationDrawer.tankAnims[1],
TextureAnimationDrawer.tankAnims[2], EntityType.TANK, bossBody, aiControl, null);
}
else
{
boss = new Tank(TextureAnimationDrawer.tankAnims[0], TextureAnimationDrawer.tankAnims[1],
TextureAnimationDrawer.tankAnims[2], EntityType.TANK, bossBody, aiControl, tankControl.getTarget());
}
bossBody.setUserData(boss);
bossBody.setFixedRotation(true);
bossBody.setLinearDamping(50.0f);
boss.addToWorldLayers(CGCWorld.getLH());
return boss;
}
示例14: createBoss
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; //导入依赖的package包/类
public Boss createBoss()
{
Boss boss;
Body bossBody;
bossBody = CGCWorld.getBF().createRectangle(9.0f, 5.0f, 1.0f, 2.0f,
BodyType.DynamicBody,
BodyFactory.CAT_STEEL_HORSE, BodyFactory.MASK_STEEL_HORSE);
boss = new SteelHorse(TextureAnimationDrawer.steelHorseAnim,
TextureAnimationDrawer.steelHorseAnim, TextureAnimationDrawer.steelHorseAnim,
EntityType.STEEL_HORSE, bossBody);
bossBody.setUserData(boss);
bossBody.setFixedRotation(true);
bossBody.setLinearDamping(0.1f);
boss.addToWorldLayers(CGCWorld.getLH());
return boss;
}
示例15: createWalls
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; //导入依赖的package包/类
public void createWalls()
{
Body b = CGCWorld.getBF().createRectangle(position.x + viewportWidth / 2, position.y+ (viewportHeight + wallHeight / 2),
viewportWidth,wallHeight, BodyType.DynamicBody,
BodyFactory.CAT_IMPASSABLE, BodyFactory.MASK_PLAYER_WALL);
upperWall = new PlayerWall(EntityType.PLAYERWALL, b, true);
b.setUserData(upperWall);
upperWall.addToWorldLayers(CGCWorld.getLH());
Body b2 = CGCWorld.getBF().createRectangle(position.x + viewportWidth / 2, position.y - viewportHeight + wallHeight / 2,
viewportWidth, wallHeight, BodyType.DynamicBody,
BodyFactory.CAT_IMPASSABLE, BodyFactory.MASK_PLAYER_WALL);
lowerWall = new PlayerWall(EntityType.PLAYERWALL, b2, false);
b2.setUserData(lowerWall);
lowerWall.addToWorldLayers(CGCWorld.getLH());
}