本文整理汇总了Java中com.badlogic.gdx.physics.box2d.EdgeShape类的典型用法代码示例。如果您正苦于以下问题:Java EdgeShape类的具体用法?Java EdgeShape怎么用?Java EdgeShape使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EdgeShape类属于com.badlogic.gdx.physics.box2d包,在下文中一共展示了EdgeShape类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: defineHero
import com.badlogic.gdx.physics.box2d.EdgeShape; //导入依赖的package包/类
public void defineHero(){
BodyDef bdef = new BodyDef();
bdef.position.set(64 / TreeScreen.PPM, 32 / TreeScreen.PPM);
bdef.type = BodyDef.BodyType.DynamicBody;
b2body = world.createBody(bdef);
FixtureDef fdef = new FixtureDef();
CircleShape shape = new CircleShape();
shape.setRadius(SIZE_HERO / 2 / TreeScreen.PPM);
fdef.filter.categoryBits = TreeScreen.HERO_BIT;
fdef.filter.maskBits = TreeScreen.GROUND_BIT;
fdef.shape = shape;
b2body.createFixture(fdef).setUserData(this);
EdgeShape head = new EdgeShape();
head.set(new Vector2(-2 / TreeScreen.PPM, 6 / TreeScreen.PPM), new Vector2(2 / TreeScreen.PPM, 6 / TreeScreen.PPM));
fdef.filter.categoryBits = TreeScreen.HERO_HEAD_BIT;
fdef.shape = head;
fdef.isSensor = true;
b2body.createFixture(fdef).setUserData(this);
}
示例2: defineMario
import com.badlogic.gdx.physics.box2d.EdgeShape; //导入依赖的package包/类
private void defineMario() {
BodyDef bdef = new BodyDef();
bdef.position.set(60 / MarioBros.PPM, 32 / MarioBros.PPM);
bdef.type = BodyDef.BodyType.DynamicBody;
b2body = world.createBody(bdef);
FixtureDef fdef = new FixtureDef();
CircleShape shape = new CircleShape();
shape.setRadius(6 / MarioBros.PPM);
fdef.filter.categoryBits = MarioBros.MARIO_BIT;
fdef.filter.maskBits = MarioBros.GROUND_BIT | MarioBros.COIN_BIT | MarioBros.ITEM_BIT
| MarioBros.BRICK_BIT | MarioBros.ENEMY_BIT | MarioBros.OBJECT_BIT | MarioBros.ENEMY_HEAD_BIT;
fdef.shape = shape;
b2body.createFixture(fdef).setUserData(this);
EdgeShape head = new EdgeShape();
head.set(new Vector2(-2 / MarioBros.PPM, 7 / MarioBros.PPM), new Vector2(2 / MarioBros.PPM, 7 / MarioBros.PPM));
fdef.shape = head;
fdef.filter.categoryBits = MarioBros.MARIO_HEAD_BIT;
fdef.isSensor = true;
b2body.createFixture(fdef).setUserData(this);
}
示例3: WorldEdge
import com.badlogic.gdx.physics.box2d.EdgeShape; //导入依赖的package包/类
public WorldEdge(World world, WorldEdgeType type){
BodyDef edgeBody = new BodyDef();
edgeBody.type = BodyDef.BodyType.StaticBody;
if (type.equals(WorldEdgeType.Right)){
edgeBody.position.set(GameMain.WIDTH / GameMain.PIXELS_TO_METERS, 0);
}else{
edgeBody.position.set(0, 0);
}
FixtureDef edgeDef = new FixtureDef();
edgeDef.filter.categoryBits = GameMain.WORLD_ENTITY;
edgeDef.filter.maskBits = GameMain.METEOR_ENTITY;
EdgeShape edge = new EdgeShape();
edge.set(0, 0, 0, GameMain.HEIGHT);
edgeDef.shape = edge;
body = world.createBody(edgeBody);
body.createFixture(edgeDef);
edge.dispose();
}
示例4: createBody
import com.badlogic.gdx.physics.box2d.EdgeShape; //导入依赖的package包/类
/**
* Creates the body.
*/
@Override
public void createBody()
{
bodyDef.position.x = x / B2FlxB.RATIO;
bodyDef.position.y = y / B2FlxB.RATIO;
position = bodyDef.position;
body = B2FlxB.world.createBody(bodyDef);
EdgeShape s;
for(int i = 0; i < shapes.length; i++)
{
s = shapes[i];
fixtureDef.shape = s;
body.createFixture(fixtureDef);
s.dispose();
s = null;
}
shape = null;
}
示例5: addEdge
import com.badlogic.gdx.physics.box2d.EdgeShape; //导入依赖的package包/类
private static void addEdge(Body body, float startX, float startY, float endX, float endY) {
EdgeShape shape = new EdgeShape();
shape.set(startX, startY, endX, endY);
FixtureDef fixture = new FixtureDef();
fixture.shape = shape;
fixture.density = 1f;
body.createFixture(fixture).setUserData(new FixtureUserData(UserDataType.LOS_BLOCKER_TILE));
shape.dispose();
}
示例6: createBoundry
import com.badlogic.gdx.physics.box2d.EdgeShape; //导入依赖的package包/类
public static Entity createBoundry (Vector2 start, Vector2 end) {
Entity entity = builder.createEntity(EntityCategory.WALL, new Vector2(0, 0)).physicsBody(BodyType.StaticBody)
.getWithoutAdding();
FixtureDef def = new FixtureDef();
EdgeShape edge = new EdgeShape();
edge.set(start, end);
def.shape = edge;
def.filter.categoryBits = EntityCategory.WALL;
Components.PHYSICS.get(entity).getBody().createFixture(edge, 1.0f);
engine.addEntity(entity);
return entity;
}
示例7: redefineHero
import com.badlogic.gdx.physics.box2d.EdgeShape; //导入依赖的package包/类
public void redefineHero(){
Vector2 position = b2body.getPosition();
world.destroyBody(b2body);
BodyDef bdef = new BodyDef();
bdef.position.set(position);
bdef.type = BodyDef.BodyType.DynamicBody;
b2body = world.createBody(bdef);
FixtureDef fdef = new FixtureDef();
CircleShape shape = new CircleShape();
shape.setRadius(6 / TreeScreen.PPM);
fdef.filter.categoryBits = TreeScreen.HERO_BIT;
fdef.filter.maskBits = TreeScreen.GROUND_BIT;
fdef.shape = shape;
b2body.createFixture(fdef).setUserData(this);
EdgeShape head = new EdgeShape();
head.set(new Vector2(-2 / TreeScreen.PPM, 6 / TreeScreen.PPM), new Vector2(2 / TreeScreen.PPM, 6 / TreeScreen.PPM));
fdef.filter.categoryBits = TreeScreen.HERO_HEAD_BIT;
fdef.shape = head;
fdef.isSensor = true;
b2body.createFixture(fdef).setUserData(this);
timeToRedefineHero = false;
}
示例8: redefineMario
import com.badlogic.gdx.physics.box2d.EdgeShape; //导入依赖的package包/类
private void redefineMario() {
Vector2 currentPosition = b2body.getPosition();
world.destroyBody(b2body);
BodyDef bdef = new BodyDef();
bdef.position.set(currentPosition);
bdef.type = BodyDef.BodyType.DynamicBody;
b2body = world.createBody(bdef);
FixtureDef fdef = new FixtureDef();
CircleShape shape = new CircleShape();
shape.setRadius(6 / MarioBros.PPM);
fdef.filter.categoryBits = MarioBros.MARIO_BIT;
fdef.filter.maskBits = MarioBros.GROUND_BIT | MarioBros.COIN_BIT | MarioBros.ITEM_BIT
| MarioBros.BRICK_BIT | MarioBros.ENEMY_BIT | MarioBros.OBJECT_BIT | MarioBros.ENEMY_HEAD_BIT;
fdef.shape = shape;
b2body.createFixture(fdef).setUserData(this);
EdgeShape head = new EdgeShape();
head.set(new Vector2(-2 / MarioBros.PPM, 7 / MarioBros.PPM), new Vector2(2 / MarioBros.PPM, 7 / MarioBros.PPM));
fdef.shape = head;
fdef.filter.categoryBits = MarioBros.MARIO_HEAD_BIT;
fdef.isSensor = true;
b2body.createFixture(fdef).setUserData(this);
timeToRedefineMario = false;
}
示例9: defineBigMario
import com.badlogic.gdx.physics.box2d.EdgeShape; //导入依赖的package包/类
private void defineBigMario() {
Vector2 currentPosition = b2body.getPosition();
world.destroyBody(b2body);
BodyDef bdef = new BodyDef();
bdef.position.set(currentPosition.add(0, 10 / MarioBros.PPM));
bdef.type = BodyDef.BodyType.DynamicBody;
b2body = world.createBody(bdef);
FixtureDef fdef = new FixtureDef();
CircleShape shape = new CircleShape();
shape.setRadius(6 / MarioBros.PPM);
fdef.filter.categoryBits = MarioBros.MARIO_BIT;
fdef.filter.maskBits = MarioBros.GROUND_BIT | MarioBros.COIN_BIT | MarioBros.ITEM_BIT
| MarioBros.BRICK_BIT | MarioBros.ENEMY_BIT | MarioBros.OBJECT_BIT | MarioBros.ENEMY_HEAD_BIT;
fdef.shape = shape;
b2body.createFixture(fdef).setUserData(this);
shape.setPosition(new Vector2(0, -14 / MarioBros.PPM));
b2body.createFixture(fdef).setUserData(this);
EdgeShape head = new EdgeShape();
head.set(new Vector2(-2 / MarioBros.PPM, 7 / MarioBros.PPM), new Vector2(2 / MarioBros.PPM, 7 / MarioBros.PPM));
fdef.shape = head;
fdef.filter.categoryBits = MarioBros.MARIO_HEAD_BIT;
fdef.isSensor = true;
b2body.createFixture(fdef).setUserData(this);
timeToDefineBigMario = false;
}
示例10: createEdge
import com.badlogic.gdx.physics.box2d.EdgeShape; //导入依赖的package包/类
private Body createEdge (BodyType type, float x1, float y1, float x2, float y2, float density) {
BodyDef def = new BodyDef();
def.type = type;
Body box = world.createBody(def);
EdgeShape poly = new EdgeShape();
poly.set(new Vector2(0, 0), new Vector2(x2 - x1, y2 - y1));
box.createFixture(poly, density);
box.setTransform(x1, y1, 0);
poly.dispose();
return box;
}
示例11: createPolygonBody
import com.badlogic.gdx.physics.box2d.EdgeShape; //导入依赖的package包/类
/**
* Genera un pol�gono
* @param world El mundo
* @param x Posici�n x
* @param y Posici�n y
* @return El cuerpo creado
*/
public static Body createPolygonBody(World world, float x, float y, float width, float height) {
// Define un cuerpo f�sico din�mico con posici�n en el mundo 2D
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.StaticBody;
//bodyDef.position.set(x, y);
Body body = world.createBody(bodyDef);
// Define una forma circular de 6 unidades de di�metro
EdgeShape polygon = new EdgeShape();
polygon.set(new Vector2(x, y), new Vector2(x + width, y + height));
// Define un elemento f�sico y sus propiedades y le asigna la forma circular
FixtureDef fixtureDef = new FixtureDef();
// Forma del elemento f�sico
fixtureDef.shape = polygon;
// Densidad (kg/m^2)
fixtureDef.density = 1f;
// Coeficiente de fricci�n (0 - 1)
fixtureDef.friction = 0.1f;
// Elasticidad (0 - 1)
fixtureDef.restitution = 0.2f;
// A�ade el elemento f�sico al cuerpo del mundo 2D
Fixture fixture = body.createFixture(fixtureDef);
polygon.dispose();
return body;
}
示例12: createPolygonBody
import com.badlogic.gdx.physics.box2d.EdgeShape; //导入依赖的package包/类
/**
* Genera un pol�gono
* @param world El mundo
* @param x Posici�n x
* @param y Posici�n y
* @return El cuerpo creado
*/
public static Body createPolygonBody(World world, float x, float y, float width, float height) {
// Define un cuerpo f�sico din�mico con posici�n en el mundo 2D
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.StaticBody;
//bodyDef.position.set(x, y);
Body body = world.createBody(bodyDef);
// Define una forma circular de 6 unidades de di�metro
EdgeShape polygon = new EdgeShape();
polygon.set(new Vector2(x, y), new Vector2(x + width, y + height));
// Define un elemento f�sico y sus propiedades y le asigna la forma circular
FixtureDef fixtureDef = new FixtureDef();
// Forma del elemento f�sico
fixtureDef.shape = polygon;
// Densidad (kg/m^2)
fixtureDef.density = 1f;
// Coeficiente de fricci�n (0 - 1)
fixtureDef.friction = 1f;
// Elasticidad (0 - 1)
fixtureDef.restitution = 0.2f;
// A�ade el elemento f�sico al cuerpo del mundo 2D
Fixture fixture = body.createFixture(fixtureDef);
polygon.dispose();
return body;
}
示例13: FixtureSerializer
import com.badlogic.gdx.physics.box2d.EdgeShape; //导入依赖的package包/类
public FixtureSerializer(RubeScene scene, Json json)
{
this.scene = scene;
chainShapeSerializer = new ChainShapeSerializer();
json.setSerializer(PolygonShape.class, new PolygonShapeSerializer());
json.setSerializer(EdgeShape.class, new EdgeShapeSerializer());
json.setSerializer(CircleShape.class, new CircleShapeSerializer());
json.setSerializer(ChainShape.class, chainShapeSerializer);
}
示例14: defineHero
import com.badlogic.gdx.physics.box2d.EdgeShape; //导入依赖的package包/类
public void defineHero() {
BodyDef bdef = new BodyDef();
bdef.position.set(50 / NoObjectionGame.PPM, 200 / NoObjectionGame.PPM);
bdef.type = BodyDef.BodyType.DynamicBody;
b2body = world.createBody(bdef);
//fixture1
FixtureDef fdef1 = new FixtureDef();
PolygonShape shape = new PolygonShape();
shape.setAsBox(5 / NoObjectionGame.PPM, 18 / NoObjectionGame.PPM);
fdef1.filter.categoryBits = NoObjectionGame.HERO_BIT;
fdef1.filter.maskBits = NoObjectionGame.DEFAULT_BIT | NoObjectionGame.DOOR_BIT | NoObjectionGame.LADDER_BIT|
NoObjectionGame.FLOOR_BIT | NoObjectionGame.MUSHROOM;
fdef1.shape = shape;
b2body.createFixture(fdef1);
EdgeShape right = new EdgeShape();
right.set(new Vector2(6 / NoObjectionGame.PPM, -10 / NoObjectionGame.PPM), new Vector2(6 / NoObjectionGame.PPM, 10 / NoObjectionGame.PPM));
fdef1.shape = right;
fdef1.isSensor = true;
//fixture2
FixtureDef fdef2 = new FixtureDef();
fdef2.filter.categoryBits = NoObjectionGame.HERO_BIT;
fdef2.filter.maskBits = NoObjectionGame.DEFAULT_BIT | NoObjectionGame.DOOR_BIT |
NoObjectionGame.LADDER_BIT| NoObjectionGame.FLOOR_BIT | NoObjectionGame.MUSHROOM;
fdef2.shape = shape;
b2body.createFixture(fdef2);
EdgeShape left = new EdgeShape();
left.set(new Vector2(-6 / NoObjectionGame.PPM, -10 / NoObjectionGame.PPM), new Vector2(-6 / NoObjectionGame.PPM, 10 / NoObjectionGame.PPM));
fdef2.shape = left;
fdef2.isSensor = true;
//fixture3
FixtureDef fdef3 = new FixtureDef();
fdef3.filter.categoryBits = NoObjectionGame.HERO_BIT;
fdef3.filter.maskBits = NoObjectionGame.DEFAULT_BIT | NoObjectionGame.DOOR_BIT |
NoObjectionGame.LADDER_BIT | NoObjectionGame.FLOOR_BIT | NoObjectionGame.MUSHROOM;
fdef3.shape = shape;
b2body.createFixture(fdef3);
EdgeShape bottom = new EdgeShape();
bottom.set(new Vector2(5 / NoObjectionGame.PPM, -19 / NoObjectionGame.PPM), new Vector2(-5 / NoObjectionGame.PPM, -19 / NoObjectionGame.PPM));
fdef3.shape = bottom;
fdef3.isSensor = true;
b2body.createFixture(fdef1).setUserData("right");
b2body.createFixture(fdef2).setUserData("left");
b2body.createFixture(fdef3).setUserData("bottom");
}
示例15: create
import com.badlogic.gdx.physics.box2d.EdgeShape; //导入依赖的package包/类
@Override
public void create () {
batch = new SpriteBatch();
Box2D.init();
mundo = new World(new Vector2(0, -9.8f), true);
debugRenderer = new Box2DDebugRenderer();
//crear la camara del mundo box2d
camaramundo = new OrthographicCamera();
camaramundo.setToOrtho(false, SCREEN_WIDTH/units, SCREEN_HEIGHT/units);
//OBJETO PISO
BodyDef cuerpoPiso = new BodyDef();
cuerpoPiso.type = BodyType.StaticBody;
//creamos una l�nea que representa el suelo, del ancho de la pantalla
EdgeShape linea = new EdgeShape();
linea.set(0, 20/units, SCREEN_WIDTH/units, 20/units);
//creamos el fixture
FixtureDef fixDef=new FixtureDef();
fixDef.shape=linea;
fixDef.filter.categoryBits = BIT_PISO;
fixDef.filter.maskBits = BIT_PELOTA | BIT_CAJA;
//lo a�adimos al mundo
piso = mundo.createBody(cuerpoPiso);
piso.createFixture(fixDef).setUserData("piso"); // a�adimos el fixture al objeto
//PAREDES
cuerpoPiso.type = BodyType.StaticBody;
//creamos una l�nea que representa la pared izquierda, del alto de la pantalla
linea.set(0, 0, 0 , SCREEN_HEIGHT*2/units);
//creamos el fixture
fixDef.shape=linea;
fixDef.filter.categoryBits = BIT_PISO;
fixDef.filter.maskBits = BIT_PELOTA | BIT_CAJA;
//lo a�adimos al mundo
piso = mundo.createBody(cuerpoPiso);
piso.createFixture(fixDef).setUserData("pared"); // a�adimos el fixture al objeto
cuerpoPiso.type = BodyType.StaticBody;
//creamos una l�nea que representa la pared derecha, del alto de la pantalla
linea.set(SCREEN_WIDTH/units, 0, SCREEN_WIDTH/units , SCREEN_HEIGHT*2/units);
//creamos el fixture
fixDef.shape=linea;
fixDef.filter.categoryBits = BIT_PISO;
fixDef.filter.maskBits = BIT_PELOTA | BIT_CAJA;
//lo a�adimos al mundo
piso = mundo.createBody(cuerpoPiso);
piso.createFixture(fixDef).setUserData("pared"); // a�adimos el fixture al objeto
//OBJETO CAJA GIRATORIA
BodyDef cuerpoCaja = new BodyDef();
cuerpoCaja.type = BodyType.KinematicBody;
cuerpoCaja.position.set(SCREEN_WIDTH/2/units, SCREEN_HEIGHT/4/units);
//creamos un rect�ngulo que representa la caja giratoria
PolygonShape rectangulo = new PolygonShape();
rectangulo.setAsBox(100/units, 10/units);
//creamos el fixture
fixDef.shape=rectangulo;
fixDef.filter.categoryBits = BIT_CAJA;
fixDef.filter.maskBits = BIT_PELOTA;
//lo a�adimos al mundo
caja = mundo.createBody(cuerpoCaja);
caja.createFixture(fixDef).setUserData("caja"); // a�adimos el fixture al objeto
//es importante hacer dispose de los shapes despues de usarlos
rectangulo.dispose();
linea.dispose();
}