本文整理汇总了Java中com.badlogic.gdx.physics.box2d.PolygonShape.set方法的典型用法代码示例。如果您正苦于以下问题:Java PolygonShape.set方法的具体用法?Java PolygonShape.set怎么用?Java PolygonShape.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.physics.box2d.PolygonShape
的用法示例。
在下文中一共展示了PolygonShape.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makePolygonGround
import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
/**
* Creates polygon ground from the given object, at the given world.
*
* @param world The world were the ground will be.
* @param object The object used to initialize the ground.
* @return The body of the created ground.
*/
static Body makePolygonGround(World world, PolygonMapObject object) {
Polygon polygon = object.getPolygon();
// Body and Fixture variables
BodyDef bdef = new BodyDef();
FixtureDef fdef = new FixtureDef();
PolygonShape shape = new PolygonShape();
bdef.type = BodyDef.BodyType.StaticBody;
bdef.position.set(PIXEL_TO_METER * polygon.getX(), PIXEL_TO_METER * polygon.getY());
Body body = world.createBody(bdef);
float[] new_vertices = polygon.getVertices().clone();
for (int i = 0; i < new_vertices.length; i++)
new_vertices[i] *= PIXEL_TO_METER;
shape.set(new_vertices);
fdef.shape = shape;
fdef.filter.categoryBits = GROUND_BIT;
body.createFixture(fdef);
return body;
}
示例2: createPolygonShape
import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
/**
* Creates a polygon shape from a pixel based list of vertices
*
* @param vertices Vertices defining an image in pixels
* @param size Width/Height of the bitmap the vertices were extracted from
* @return A PolygonShape with the correct vertices
*/
static PolygonShape createPolygonShape(float[] vertices, Vector2 size) {
// Transform pixels into meters, center and invert the y-coordinate
for (int i = 0; i < vertices.length; i++) {
if (i % 2 == 0) vertices[i] -= size.x / 2; // center the vertex x-coordinate
if (i % 2 != 0) vertices[i] -= size.y / 2; // center the vertex y-coordinate
if (i % 2 != 0) vertices[i] *= -1; // invert the y-coordinate
vertices[i] *= PIXEL_TO_METER; // scale from pixel to meter
}
PolygonShape polygon = new PolygonShape();
polygon.set(vertices);
return polygon;
}
示例3: circleToSquare
import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
/**
* Because the algorithm is based on vertices, and the circles do not have vertices, we create a square around it.
* @param fixture Circle fixture
* @return A square instead of the circle
*/
private static PolygonShape circleToSquare(Fixture fixture) {
Vector2 position = fixture.getBody().getLocalCenter();
float x = position.x;
float y = position .y;
float radius = fixture.getShape().getRadius();
PolygonShape octagon = new PolygonShape();
Vector2[] vertices = new Vector2[4];
vertices[0] = new Vector2(x-radius, y+radius);
vertices[1]= new Vector2(x+radius, y+radius);
vertices[2]= new Vector2(x-radius, y-radius);
vertices[3]= new Vector2(x+radius, y-radius);
octagon.set((Vector2[]) vertices);
return octagon;
}
示例4: createPolygon
import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
/**
* Erzeugt aus einem PolygonMapObject ein PolygonShape.
*
* @param polyObject das MapObject
* @return die entsprechende Form
*/
public static PolygonShape createPolygon(PolygonMapObject polyObject)
{
PolygonShape polygon = new PolygonShape();
float[] vertices = polyObject.getPolygon().getTransformedVertices();
Vector2[] worldVertices = new Vector2[vertices.length / 2];
if (worldVertices.length > 8)
{
Gdx.app.error("ERROR", "Too many polygon vertices. A polygon may have up to 8 vertices but no more.");
return null;
}
for (int i = 0; i < vertices.length / 2; i++)
{
worldVertices[i] = new Vector2();
worldVertices[i].x = vertices[i * 2] * Physics.MPP;
worldVertices[i].y = vertices[i * 2 + 1] * Physics.MPP;
}
polygon.set(worldVertices);
return polygon;
}
示例5: apply
import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
@Override
public void apply () {
Body body = ((Rigidbody)getParent().getComponentByType(ComponentType.Rigidbody)).getBody();
FixtureDef fixtureDef = new FixtureDef();
PolygonShape shape = new PolygonShape();
fixture.setDensity(1);
fixture.setDensity(density);
shape.set((Vector2[])vertecies.toArray(Vector2.class));
fixtureDef.density = 4;
fixtureDef.friction = friction;
fixtureDef.isSensor = isSensor;
fixtureDef.restitution = restitution;
fixtureDef.shape = shape;
if (fixtures.size > 0) {
dispose();
fixtures.clear();
((Rigidbody)getParent().getComponentByType(ComponentType.Rigidbody)).apply();
rebuildAll();
return;
}
B2DSeparator.separate(body, fixtureDef, (Vector2[])vertecies.toArray(Vector2.class), this);
fixture = body.createFixture(fixtureDef);
fixture.setFilterData(filter);
}
示例6: SpikeEntity
import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
/**
* Create some spike
*
* @param world
* @param texture
* @param x horizontal position for the center of the spike (meters)
* @param y vertical position for the base of the spike (meters)
*/
public SpikeEntity(World world, Texture texture, float x, float y) {
this.world = world;
this.texture = texture;
// Create the body.
BodyDef def = new BodyDef(); // (1) Give it some definition.
def.position.set(x, y + 0.5f); // (2) Position the body on the world.
body = world.createBody(def); // (3) Create the body.
// Now give it a shape.
PolygonShape box = new PolygonShape(); // (1) We will make a polygon.
Vector2[] vertices = new Vector2[3]; // (2) However vertices will be manually added.
vertices[0] = new Vector2(-0.5f, -0.5f); // (3) Add the vertices for a triangle.
vertices[1] = new Vector2(0.5f, -0.5f);
vertices[2] = new Vector2(0, 0.5f);
box.set(vertices); // (4) And put them in the shape.
fixture = body.createFixture(box, 1); // (5) Create the fixture.
fixture.setUserData("spike"); // (6) And set the user data to enemy.
box.dispose(); // (7) Destroy the shape when you don't need it.
// Position the actor in the screen by converting the meters to pixels.
setPosition((x - 0.5f) * Constants.PIXELS_IN_METER, y * Constants.PIXELS_IN_METER);
setSize(Constants.PIXELS_IN_METER, Constants.PIXELS_IN_METER);
}
示例7: createBlockBody
import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
private void createBlockBody() {
if(type!=1){
BodyDef blockBodyDef = new BodyDef();
blockBodyDef.type = BodyDef.BodyType.StaticBody;
blockBodyDef.position.set(posX, posY);
FixtureDef blockFixtureDef = new FixtureDef();
Vector2[] vect = vectorTabFromRect(rect);
PolygonShape polyShape = new PolygonShape();
polyShape.set(vect);
blockFixtureDef.shape = polyShape;
body = world.createBody(blockBodyDef);
body.createFixture(blockFixtureDef);
}
}
示例8: initBodies
import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
@Override
protected void initBodies(PointF worldPos) {
// Cuerpo
{
// Create Shape with Properties
PolygonShape polygonShape = new PolygonShape();
Vector2[] vertices = new Vector2[] {
new Vector2(0, mRadius),
new Vector2(-mRadius, 0),
new Vector2(0, -mRadius),
new Vector2(mRadius, 0) };
polygonShape.set(vertices);
mMainBody = getWorld().createBody(this, worldPos, true);
mMainBody.setBullet(true);
// Assign shape to Body
Fixture f = mMainBody.createFixture(polygonShape, 1.0f);
f.setFilterData(CONTACT_FILTER);
polygonShape.dispose();
}
mAnthtopoDelegate.createAnthropomorphicLimbs(worldPos, mRadius);
}
示例9: triangleEntity
import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
private static Body triangleEntity(World world, Entity entity, float x, float y, float width, float height) {
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DynamicBody;
bodyDef.position.set(x, y);
Body body = world.createBody(bodyDef);
body.setUserData(entity);
PolygonShape shape = new PolygonShape();
Vector2[] vertices = { new Vector2(-width / 2, -height / 2),
new Vector2(width / 2, -height / 2), new Vector2(0, height / 2) };
shape.set(vertices);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = shape;
fixtureDef.density = 0.5f;
fixtureDef.friction = 0.4f;
fixtureDef.restitution = 0;
body.createFixture(fixtureDef);
return body;
}
示例10: rectangleEntity
import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
private static Body rectangleEntity(World world, Entity entity, float x, float y, float width, float height, float angle) {
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DynamicBody;
bodyDef.position.set(x, y);
Body body = world.createBody(bodyDef);
body.setUserData(entity);
body.setTransform(x, y, angle);
PolygonShape shape = new PolygonShape();
Vector2[] vertices = { new Vector2(-width / 2, height / 2),
new Vector2(-width / 2, -height / 2),
new Vector2(width / 2, -height / 2),
new Vector2(width / 2, height / 2) };
shape.set(vertices);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = shape;
fixtureDef.density = 0.5f;
fixtureDef.friction = 0.4f;
fixtureDef.restitution = 0;
body.createFixture(fixtureDef);
return body;
}
示例11: createFixtureDef
import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
@Override
public FixtureDef createFixtureDef(float metersPerUnit) {
PolygonShape shape = new PolygonShape();
// TODO: gc?
Vector2[] scaledVertices = new Vector2[vertices.length];
for (int i = 0; i < vertices.length; i++) {
scaledVertices[i] = vertices[i].scl(metersPerUnit);
}
shape.set(scaledVertices);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = shape;
fixtureDef.density = material.getDensity();
fixtureDef.friction = material.getFriction();
fixtureDef.restitution = material.getRestitution();
return fixtureDef;
}
示例12: createTerrainTile
import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
/**
* Creates a specific tile for the terrain
*
* @param world the world that the tile is to be placed in
* @param position the position at which the tile should be started at
* @param angle the angle to rotate the tile by
* @return the assembled physics body for the terrain tile
*/
private static Body createTerrainTile(World world, Vector2 position, double angle) {
// Create the physics body for the tile
BodyDef tileBodyDef = new BodyDef();
tileBodyDef.position.set(position);
Body tileBody = world.createBody(tileBodyDef);
FixtureDef tileFixDef = new FixtureDef();
// Create the vertices for shape of the tile
Vector2[] tileVertices = new Vector2[4];
tileVertices[0] = new Vector2(0, 0);
tileVertices[1] = new Vector2(0, GROUND_PIECE_HEIGHT);
tileVertices[2] = new Vector2(GROUND_PIECE_WIDTH, GROUND_PIECE_HEIGHT);
tileVertices[3] = new Vector2(GROUND_PIECE_WIDTH, 0);
PolygonShape tileShape = new PolygonShape();
tileShape.set(rotateTileVertices(tileVertices, angle));
tileFixDef.shape = tileShape;
tileFixDef.friction = 0.5f;
tileBody.createFixture(tileFixDef);
return tileBody;
}
示例13: attachChassisPiece
import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
/**
* Builds a chassis piece for a car. Due to how box2d works, we are
* basically creating a series of triangles for the car. Each chassis piece
* created here is one triangle on the car body. The two vertices passed, along
* with the center point (0, 0) of the chassis will create the triangle.
*
* @param body the body to build the chassis pieces onto
* @param v1 the first vertex to use on the triangle chassis piece
* @param v2 the second vertex to use on the triangle chassis piece
*/
private static void attachChassisPiece(Body body, Vector2 v1, Vector2 v2) {
Vector2[] pieceVertexes = new Vector2[3];
pieceVertexes[0] = v1;
pieceVertexes[1] = v2;
pieceVertexes[2] = new Vector2(0f, 0f);
FixtureDef fixDef = new FixtureDef();
PolygonShape pieceShape = new PolygonShape();
pieceShape.set(pieceVertexes);
fixDef.shape = pieceShape;
fixDef.density = 80;
fixDef.friction = 10;
fixDef.restitution = 0f;
fixDef.filter.groupIndex = -1;
body.createFixture(fixDef);
}
示例14: makeFuselage
import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
private PolygonShape makeFuselage()
{
PolygonShape shape = new PolygonShape();
Vector2[] fuselage = new Vector2[8]; //
{
fuselage[0] = new Vector2(-0.5f * Ship.RAITO, 3 * Ship.RAITO); // A
fuselage[1] = new Vector2(0.5f * Ship.RAITO, 3 * Ship.RAITO); // B
fuselage[2] = new Vector2(1f * Ship.RAITO, 0.5f * Ship.RAITO); // C
fuselage[3] = new Vector2(1 * Ship.RAITO, -1 * Ship.RAITO); // D
fuselage[4] = new Vector2(0.5f * Ship.RAITO, -2 * Ship.RAITO); //E
fuselage[5] = new Vector2(-0.5f * Ship.RAITO, -2 * Ship.RAITO); //F
fuselage[6] = new Vector2(-1 * Ship.RAITO, -1 * Ship.RAITO); //G
fuselage[7] = new Vector2(-1 * Ship.RAITO, 0.5f * Ship.RAITO); //H
}
shape.set(fuselage);
return shape;
}
示例15: createStaticBody
import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
/**
* Create static body from a TiledObject Refer the box2d manual to
* understand the static body
*
* @param o
* TiledObject
*/
private Body createStaticBody(TiledObject o) {
BodyDef groundBodyDef = new BodyDef();
groundBodyDef.type = BodyType.StaticBody;
// get x from tile object
float x = o.x;
// transform into box2d
x = x * WORLD_TO_BOX;
// get position-y of object from map
float y = tileMapRenderer.getMapHeightUnits() - o.y - o.height;
// transform into box2d
y = y * WORLD_TO_BOX;
groundBodyDef.position.set(x, y);
Body groundBody = world.createBody(groundBodyDef);
PolygonShape groundBox = new PolygonShape();
// get the polygon point from map
String[] strp = o.polygon.split(" ");
Vector2[] apoints = new Vector2[strp.length];
// for each points from objects
for (int i = 0; i < strp.length; i++) {
x = Float.parseFloat(strp[i].split(",")[0]); // get x
x = x * WORLD_TO_BOX; // transform into box2d
y = -Float.parseFloat(strp[i].split(",")[1]); // get y
y = y * WORLD_TO_BOX; // transform into box2d
// insert the point into the array
apoints[i] = new Vector2(x, y);
}
// create static body from point array
groundBox.set(apoints);
groundBody.createFixture(groundBox, 0.0f);
groundBody.setUserData("static");
return groundBody;
}