当前位置: 首页>>代码示例>>Java>>正文


Java PolygonShape.setAsBox方法代码示例

本文整理汇总了Java中com.badlogic.gdx.physics.box2d.PolygonShape.setAsBox方法的典型用法代码示例。如果您正苦于以下问题:Java PolygonShape.setAsBox方法的具体用法?Java PolygonShape.setAsBox怎么用?Java PolygonShape.setAsBox使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.badlogic.gdx.physics.box2d.PolygonShape的用法示例。


在下文中一共展示了PolygonShape.setAsBox方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createWall

import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
/**
 * Creates a wall by constructing a rectangle whose corners are (xmin,ymin) and (xmax,ymax),
 * and rotating the box counterclockwise through the given angle, with specified restitution.
 */
public static Body createWall(World world, float xmin, float ymin, float xmax, float ymax,
        float angle, float restitution) {
    float cx = (xmin + xmax) / 2;
    float cy = (ymin + ymax) / 2;
    float hx = Math.abs((xmax - xmin) / 2);
    float hy = Math.abs((ymax - ymin) / 2);
    PolygonShape wallshape = new PolygonShape();
    // Don't set the angle here; instead call setTransform on the body below. This allows future
    // calls to setTransform to adjust the rotation as expected.
    wallshape.setAsBox(hx, hy, new Vector2(0f, 0f), 0f);

    FixtureDef fdef = new FixtureDef();
    fdef.shape = wallshape;
    fdef.density = 1.0f;
    if (restitution>0) fdef.restitution = restitution;

    BodyDef bd = new BodyDef();
    bd.position.set(cx, cy);
    Body wall = world.createBody(bd);
    wall.createFixture(fdef);
    wall.setType(BodyDef.BodyType.StaticBody);
    wall.setTransform(cx, cy, angle);
    return wall;
}
 
开发者ID:StringMon,项目名称:homescreenarcade,代码行数:29,代码来源:Box2DFactory.java

示例2: WaterModel

import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
/**
 * Water Model's constructor.
 * Creates a water model from the given object, into the given world.
 *
 * @param world The world the water model will be in.
 * @param rect  The rectangle to create the water model with.
 */
public WaterModel(World world, Rectangle rect) {
    // 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 * (rect.getX() + rect.getWidth() / 2), PIXEL_TO_METER * (rect.getY() + rect.getHeight() / 2));

    this.body = world.createBody(bdef);

    shape.setAsBox((rect.getWidth() / 2) * PIXEL_TO_METER, (rect.getHeight() / 2) * PIXEL_TO_METER);
    fdef.shape = shape;
    fdef.filter.categoryBits = FLUID_BIT;
    fdef.isSensor = true;
    fdef.density = 1f;
    fdef.friction = 0.1f;
    fdef.restitution = 0f;
    body.createFixture(fdef);

    body.setUserData(new BuoyancyController(world, body.getFixtureList().first()));

}
 
开发者ID:AndreFCruz,项目名称:feup-lpoo-armadillo,代码行数:31,代码来源:WaterModel.java

示例3: createBody

import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的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();
}
 
开发者ID:jocasolo,项目名称:water2d-libgdx,代码行数:27,代码来源:GameMain.java

示例4: createTopTube

import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
public static Array<Body> createTopTube(World world, float posX) {

        float posY = generateTubePosition();

        BodyDef bodyDef = new BodyDef();
        bodyDef.type = BodyDef.BodyType.KinematicBody;
        bodyDef.position.set(posX, posY);
        PolygonShape shape = new PolygonShape();
        shape.setAsBox(Constants.TUBE_WIDTH / 2, Constants.TUBE_HEIGHT / 2);
        Body bodyTop = world.createBody(bodyDef);
        bodyTop.createFixture(shape, 0f);
        bodyTop.resetMassData();
        shape.dispose();
        bodyTop.setLinearVelocity(Constants.TUBE_SPEED, 0.0f);
        Array<Body> bodies = new Array<Body>();
        bodies.add(bodyTop);
        bodies.add(createBottomTube(world, posX, posY));
        return bodies;
    }
 
开发者ID:ZephyrVentum,项目名称:FlappySpinner,代码行数:20,代码来源:WorldUtils.java

示例5: createStick

import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
/**
 * 创建攻击夹具
 */
public void createStick() {
	if (mAttackFixture != null) {
		return;
	}
	//创建攻击传感器 stick
	PolygonShape shape = new PolygonShape();
	if (STATE == State.STATE_RIGHT_ATTACK) {
		shape.setAsBox(45 / Constant.RATE, 5 / Constant.RATE
				, new Vector2(60 / Constant.RATE, 0), 0);
	} else {
		shape.setAsBox(45 / Constant.RATE, 5 / Constant.RATE
				, new Vector2(-60 / Constant.RATE, 0), 0);
	}
	FixtureDef attackFixDef = new FixtureDef();
	attackFixDef.shape = shape;
	attackFixDef.filter.categoryBits = Constant.PLAYER;
	attackFixDef.filter.maskBits = Constant.ENEMY_DAO | Constant.BOSS;
	attackFixDef.isSensor = true;
	mAttackFixture = mBody.createFixture(attackFixDef);
	mAttackFixture.setUserData("stick");
}
 
开发者ID:heyzqt,项目名称:libGdx-xiyou,代码行数:25,代码来源:Monkey.java

示例6: createJumpStick

import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
/**
 * 创建升龙斩攻击夹具
 */
public void createJumpStick() {
	if (mJumpAtkFix != null) {
		return;
	}
	//创建攻击传感器 stick
	PolygonShape shape = new PolygonShape();
	if (STATE == State.STATE_RIGHT_JUMP_ATTACK) {
		shape.setAsBox(10 / Constant.RATE, 40 / Constant.RATE
				, new Vector2(100 / Constant.RATE, 20 / Constant.RATE), 0);
	} else {
		shape.setAsBox(10 / Constant.RATE, 45 / Constant.RATE
				, new Vector2(-100 / Constant.RATE, 20 / Constant.RATE), 0);
	}
	FixtureDef attackFixDef = new FixtureDef();
	attackFixDef.shape = shape;
	attackFixDef.filter.categoryBits = Constant.PLAYER;
	attackFixDef.filter.maskBits = Constant.ENEMY_DAO | Constant.BOSS;
	attackFixDef.isSensor = true;
	mJumpAtkFix = mBody.createFixture(attackFixDef);
	mJumpAtkFix.setUserData("ball");
}
 
开发者ID:heyzqt,项目名称:libGdx-xiyou,代码行数:25,代码来源:Monkey.java

示例7: init

import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
private void init() {
	mRegion = MyGdxGame.assetManager.getTextureAtlas(Constant.PLAY_BLOOD).findRegion("mp");

	mBodyDef = new BodyDef();
	mFixtureDef = new FixtureDef();
	PolygonShape shape = new PolygonShape();

	//初始化刚体形状
	mBodyDef.type = BodyDef.BodyType.StaticBody;
	mBodyDef.position.set(x, y);

	shape.setAsBox(30 / Constant.RATE, 30 / Constant.RATE);
	mFixtureDef.shape = shape;
	mFixtureDef.isSensor = true;
	mFixtureDef.filter.categoryBits = Constant.BLUE;
	mFixtureDef.filter.maskBits = Constant.PLAYER;

	mBody = mWorld.createBody(mBodyDef);
	mBody.createFixture(mFixtureDef).setUserData("blue");
}
 
开发者ID:heyzqt,项目名称:libGdx-xiyou,代码行数:21,代码来源:Blue.java

示例8: createFixtureDef

import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
private FixtureDef createFixtureDef() {
        PolygonShape shape = new PolygonShape();
//        shape.set(new Vector2[]{
//                new Vector2(1.3f, -1.29f),
//                new Vector2(1f, -1.3f),
//                new Vector2(-1f, -1.3f),
//                new Vector2(-1.3f, -1.29f),
//                new Vector2(-1.3f, 1.29f),
//                new Vector2(-1f, 1.3f),
//                new Vector2(1f, 1.3f),
//                new Vector2(1.3f, 1.29f)
//        });
        shape.setAsBox(getWidth() * 0.49f, getHeight() * 0.459375f);

        FixtureDef fixtureDef = new FixtureDef();
        fixtureDef.shape = shape;
        fixtureDef.density = 0.71f;
        fixtureDef.friction = 0f;
        fixtureDef.restitution = 0;

        return fixtureDef;
    }
 
开发者ID:alexschimpf,项目名称:joe,代码行数:23,代码来源:Player.java

示例9: createBody

import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
@Override
protected Body createBody(final Box2DService box2d) {
    final BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.StaticBody;
    bodyDef.fixedRotation = true;

    final PolygonShape shape = new PolygonShape();
    shape.setAsBox(Block.HALF_SIZE, Block.HALF_SIZE);
    final FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.isSensor = true;
    fixtureDef.shape = shape;
    fixtureDef.filter.categoryBits = Box2DUtil.CAT_BLOCK;
    fixtureDef.filter.maskBits = Box2DUtil.MASK_BLOCK;
    final Body body = box2d.getWorld().createBody(bodyDef);
    body.createFixture(fixtureDef);
    shape.dispose();
    return body;
}
 
开发者ID:BialJam,项目名称:M-M,代码行数:19,代码来源:Bonus.java

示例10: createBody

import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
@Override
protected Body createBody(final Box2DService box2d) {
    final BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.StaticBody;
    bodyDef.fixedRotation = true;

    final PolygonShape shape = new PolygonShape();
    shape.setAsBox(HALF_SIZE, HALF_SIZE);
    final FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.restitution = 1f;
    fixtureDef.friction = 0f;
    fixtureDef.shape = shape;
    fixtureDef.filter.categoryBits = Box2DUtil.CAT_BLOCK;
    fixtureDef.filter.maskBits = Box2DUtil.MASK_BLOCK;
    final Body body = box2d.getWorld().createBody(bodyDef);
    body.createFixture(fixtureDef);
    shape.dispose();
    return body;
}
 
开发者ID:BialJam,项目名称:M-M,代码行数:20,代码来源:Block.java

示例11: Block

import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
public Block(World world, float x, float f, BodyType type, boolean invisible) {
	BodyDef bd = new BodyDef();
	bd.type = type;
	bd.position.set(x, f);
	PolygonShape shape = new PolygonShape();
	shape.setAsBox(size / 2, size / 2);
	FixtureDef fd = new FixtureDef();
	fd.density = 0.1f;
	fd.shape = shape;
	fd.friction = 0.1f;
	fd.filter.groupIndex = Advio.GROUP_DONT_COLLIDE_WITH_PLAYER;
	// fd.filter.groupIndex = Advio.GROUP_SCENERY;
	body = world.createBody(bd);
	body.createFixture(fd).setUserData(new UserData("block"));
	this.invisible = invisible;
	shape.dispose();
}
 
开发者ID:lvivtotoro,项目名称:advio,代码行数:18,代码来源:Block.java

示例12: PressurePlate

import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
public PressurePlate(Level l, World world, float x, float y, float weight, Block[] blocks) {
	super(x, y);
	this.level = l;
	BodyDef bd = new BodyDef();
	bd.type = BodyType.KinematicBody;
	bd.position.set(x, y);
	PolygonShape shape = new PolygonShape();
	shape.setAsBox(Block.size / 2, Block.size / 2);
	FixtureDef fd = new FixtureDef();
	fd.density = 0.0f;
	fd.shape = shape;
	fd.friction = 0.1f;
	fd.isSensor = true;
	this.blocks = new ArrayList<Block>(Arrays.asList(blocks));
	body = world.createBody(bd);
	body.createFixture(fd).setUserData(new UserData("plate").add("pressed", false).add("weight", weight));
	shape.dispose();
	this.world = world;
}
 
开发者ID:lvivtotoro,项目名称:advio,代码行数:20,代码来源:PressurePlate.java

示例13: AgarLogic

import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
public AgarLogic(Level l, World world, float x, float y) {
	super(x, y);
	this.level = l;
	BodyDef bd = new BodyDef();
	bd.type = BodyType.KinematicBody;
	bd.position.set(x, y);
	PolygonShape shape = new PolygonShape();
	shape.setAsBox(Block.size / 2, Block.size / 2);
	FixtureDef fd = new FixtureDef();
	fd.density = 0.0f;
	fd.shape = shape;
	fd.friction = 0.1f;
	fd.isSensor = true;
	body = world.createBody(bd);
	body.createFixture(fd).setUserData(new UserData("agariologic"));
	shape.dispose();
	this.world = world;
}
 
开发者ID:lvivtotoro,项目名称:advio,代码行数:19,代码来源:AgarLogic.java

示例14: Goal

import com.badlogic.gdx.physics.box2d.PolygonShape; //导入方法依赖的package包/类
public Goal(World world, float x, float y) {
	super(x, y);
	BodyDef bd = new BodyDef();
	bd.type = BodyType.KinematicBody;
	bd.position.set(x, y);
	PolygonShape shape = new PolygonShape();
	shape.setAsBox(Block.size / 2, Block.size / 2);
	FixtureDef fd = new FixtureDef();
	fd.density = 0.1f;
	fd.shape = shape;
	fd.friction = 0.1f;
	fd.isSensor = true;
	// fd.filter.groupIndex = Advio.GROUP_SCENERY;
	body = world.createBody(bd);
	body.createFixture(fd).setUserData(new UserData("goal"));
	shape.dispose();
}
 
开发者ID:lvivtotoro,项目名称:advio,代码行数:18,代码来源:Goal.java

示例15: 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();
	shape.setAsBox(width / 2, height / 2, new Vector2(x, y), (float)Math.toRadians(angle));
	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();
		return;
	}
	fixture = body.createFixture(fixtureDef);
	fixture.setFilterData(filter);
	UserData userdata = new UserData();
	userdata.component = (Rigidbody)getParent().getComponentByType(ComponentType.Rigidbody);
	fixture.setUserData(userdata);
}
 
开发者ID:Quexten,项目名称:RavTech,代码行数:25,代码来源:BoxCollider.java


注:本文中的com.badlogic.gdx.physics.box2d.PolygonShape.setAsBox方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。