當前位置: 首頁>>代碼示例>>Java>>正文


Java BodyType.DynamicBody方法代碼示例

本文整理匯總了Java中com.badlogic.gdx.physics.box2d.BodyDef.BodyType.DynamicBody方法的典型用法代碼示例。如果您正苦於以下問題:Java BodyType.DynamicBody方法的具體用法?Java BodyType.DynamicBody怎麽用?Java BodyType.DynamicBody使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.badlogic.gdx.physics.box2d.BodyDef.BodyType的用法示例。


在下文中一共展示了BodyType.DynamicBody方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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;
   }
 
開發者ID:game-libgdx-unity,項目名稱:GDX-Engine,代碼行數:26,代碼來源:PhysicsManager.java

示例2: 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;
}
 
開發者ID:game-libgdx-unity,項目名稱:GDX-Engine,代碼行數:21,代碼來源:Rope.java

示例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;
}
 
開發者ID:game-libgdx-unity,項目名稱:GDX-Engine,代碼行數:26,代碼來源:PhysicsTiledScene.java

示例4: 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();
}
 
開發者ID:jocasolo,項目名稱:water2d-libgdx,代碼行數:27,代碼來源:GameMain.java

示例5: WorldObject

import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; //導入方法依賴的package包/類
public WorldObject() {
    this.id = nextId++;
    this.destroyed = false;
    this.boundingQueue = new ObjectSet<>();
    this.def = new BodyDef();
    this.persistent = false;
    this.visible = true;
    this.layer = 0;

    this.def.active = true;
    this.def.awake = true;
    this.def.fixedRotation = true;
    this.def.type = BodyType.DynamicBody;

    this.groupId = -1;
    this.canCollide = true;
    this.events = new EventHelper(this);
}
 
開發者ID:Xemiru,項目名稱:Undertailor,代碼行數:19,代碼來源:WorldObject.java

示例6: Player

import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; //導入方法依賴的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
}
 
開發者ID:lvivtotoro,項目名稱:advio,代碼行數:21,代碼來源:Player.java

示例7: Enemy

import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; //導入方法依賴的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();
}
 
開發者ID:lvivtotoro,項目名稱:advio,代碼行數:20,代碼來源:Enemy.java

示例8: SetBody

import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; //導入方法依賴的package包/類
private BodyComponent SetBody(String name)
{
	BodyDef bodyDef = new BodyDef();
	bodyDef.position.set(_position.x, _position.y);
	bodyDef.type = BodyType.DynamicBody;
	bodyDef.fixedRotation = _descriptor.FixedRotation;
	FixtureDef fixtureDef = new FixtureDef();
	fixtureDef.density = _descriptor.Density;
	fixtureDef.friction = 0.7f;
	fixtureDef.restitution = 0f;
	_bodyCompo = new BodyComponent(name, this, _box2DWorld, _bodyDAL, bodyDef, fixtureDef);
	_bodyCompo.setActive(false);
	_bodyCompo.setUserData(this);
	addComponent(_bodyCompo);
	return _bodyCompo;
}
 
開發者ID:mitsuhirato,項目名稱:TheEndlessCastle,代碼行數:17,代碼來源:ProjectileEntity.java

示例9: initBody

import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; //導入方法依賴的package包/類
public static Body initBody(World world, float x, float y, float width, float height, boolean rotate, float gravityScale, float density)
{
	BodyDef bodyDef = new BodyDef();
	bodyDef.position.set((x + width / 2), (y + height / 2));

	bodyDef.fixedRotation = !rotate;
	bodyDef.type = BodyType.DynamicBody;

	Body body = world.createBody(bodyDef);
	body.setGravityScale(gravityScale);

	PolygonShape shape = new PolygonShape();
	shape.setAsBox((width / 2), (height / 2));
	body.createFixture(shape, density);
	shape.dispose();

	return body;
}
 
開發者ID:kLeZ,項目名稱:LibGDX-MVC-Tutorial,代碼行數:19,代碼來源:Helpers.java

示例10: Player

import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; //導入方法依賴的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();
}
 
開發者ID:zozotintin,項目名稱:Dodgy-Dot,代碼行數:22,代碼來源:GameScreen.java

示例11: Ball

import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; //導入方法依賴的package包/類
public Ball(World world, float x, float y) {
	
	BodyDef bodyDef = new BodyDef();
	FixtureDef fixtureDef = new FixtureDef();
	this.world = world;
	
	// body definition
	bodyDef.type = BodyType.DynamicBody;
	bodyDef.position.set(x, y);

	// ball shape
	CircleShape ballShape = new CircleShape();
	ballShape.setRadius(RADIUS);

	// fixture definition
	fixtureDef.shape = ballShape;
	fixtureDef.friction = 0;
	fixtureDef.restitution = 1;
	//fixtureDef.density = 0;
	
	body = world.createBody(bodyDef);
	fixture = body.createFixture(fixtureDef);
	
	ballShape.dispose();
}
 
開發者ID:CODA-Masters,項目名稱:Pong-Tutorial,代碼行數:26,代碼來源:Ball.java

示例12: Player

import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; //導入方法依賴的package包/類
public Player(World world, Vector2 position, OrthographicCamera camera, GameScreen screen) {
	this.world = world;
	this.camera = camera;
       this.screen = screen;
	
	hWidth = .6f;
	hHeight = 1;

       dragVector = new Vector2();
       dragRatio = new Vector2();
	
	glow = new Sprite(new Texture(Gdx.files.internal("glow.png")));
	
	bodyDef = new BodyDef();
	bodyDef.type = BodyType.DynamicBody;
	bodyDef.position.set(position);
	
	body = world.createBody(bodyDef);
	body.setUserData(Assets.playerAnimations);
	PolygonShape shape = new PolygonShape();
	shape.setAsBox(hWidth, hHeight);
	body.setFixedRotation(true);
	body.createFixture(shape, 1);
	
	shape.dispose();
}
 
開發者ID:mcprog,項目名稱:ragnar,代碼行數:27,代碼來源:Player.java

示例13: Arrow

import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; //導入方法依賴的package包/類
public Arrow(World world, Vector2 position, float rotation) {
	this.world = world;
	bodyDef = new BodyDef();
	bodyDef.type = BodyType.DynamicBody;
	this.position = position;
	bodyDef.position.set(position);
	
	PolygonShape shape = new PolygonShape();
	shape.setAsBox(1.5f, .1f);
	
	movementRaw = new Vector2((float)(-Math.cos(rotation)), (float)(-Math.sin(rotation)));
	movementRaw.scl((float) (Math.random() * 5) + 15);
	body = world.createBody(bodyDef);
	body.createFixture(shape, 1);
	shape.dispose();
	body.setTransform(position, rotation);
	body.setFixedRotation(true);// TODO maybe change.
	body.setLinearVelocity(movementRaw);
	body.setUserData("arrow");
	
	
	
}
 
開發者ID:mcprog,項目名稱:ragnar,代碼行數:24,代碼來源:Arrow.java

示例14: Item

import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; //導入方法依賴的package包/類
public Item(int i, int ei, String c, int a, float f, float g, float h,
        EquipType et, ItemType type, Attributes a1, int wId)
{
    super((int) h);
    this.id = i;
    this.caption = c;
    this.amount = a;
    this.entityId = ei;
    this.eqType = et;
    this.type = type;
    this.attributes = a1;
    this.worldId = wId;
    this.allAround = new ArrayList<IUpdate>();

    bodyDef = new BodyDef();
    bodyDef.type = BodyType.DynamicBody;
    bodyDef.position.set(f, g);
    bodyDef.linearDamping = 1.6F;

    Server.SaveItem(this);
}
 
開發者ID:MosaicOwl,項目名稱:the-erder,代碼行數:22,代碼來源:Item.java

示例15: createSteeringEntity

import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; //導入方法依賴的package包/類
public Box2dSteeringEntity createSteeringEntity (World world, TextureRegion region, boolean independentFacing, int posX, int posY) {

		CircleShape circleChape = new CircleShape();
		circleChape.setPosition(new Vector2());
		int radiusInPixels = (int)((region.getRegionWidth() + region.getRegionHeight()) / 4f);
		circleChape.setRadius(Box2dSteeringTest.pixelsToMeters(radiusInPixels));

		BodyDef characterBodyDef = new BodyDef();
		characterBodyDef.position.set(Box2dSteeringTest.pixelsToMeters(posX), Box2dSteeringTest.pixelsToMeters(posY));
		characterBodyDef.type = BodyType.DynamicBody;
		Body characterBody = world.createBody(characterBodyDef);

		FixtureDef charFixtureDef = new FixtureDef();
		charFixtureDef.density = 1;
		charFixtureDef.shape = circleChape;
		charFixtureDef.filter.groupIndex = 0;
		characterBody.createFixture(charFixtureDef);

		circleChape.dispose();

		return new Box2dSteeringEntity(region, characterBody, independentFacing, Box2dSteeringTest.pixelsToMeters(radiusInPixels));
	}
 
開發者ID:libgdx,項目名稱:gdx-ai,代碼行數:23,代碼來源:Box2dSteeringTest.java


注:本文中的com.badlogic.gdx.physics.box2d.BodyDef.BodyType.DynamicBody方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。