本文整理匯總了Java中com.badlogic.gdx.physics.box2d.World.destroyBody方法的典型用法代碼示例。如果您正苦於以下問題:Java World.destroyBody方法的具體用法?Java World.destroyBody怎麽用?Java World.destroyBody使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.badlogic.gdx.physics.box2d.World
的用法示例。
在下文中一共展示了World.destroyBody方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: update
import com.badlogic.gdx.physics.box2d.World; //導入方法依賴的package包/類
public void update(World world) {
for (int i = 0; i < balls.size; i++) {
FireBall ball = balls.get(i);
//檢查火球速度異常情況
if (ball.getBody().getLinearVelocity().x == 0.2f && ball.STATE == State.STATE_RIGHT_FIREBALL) {
ball.getBody().setLinearVelocity(1.0f, 0);
} else if (ball.getBody().getLinearVelocity().x == -0.2f && ball.STATE == State.STATE_RIGHT_FIREBALL) {
ball.getBody().setLinearVelocity(1.0f, 0);
} else if (ball.getBody().getLinearVelocity().x == 0.2f && ball.STATE == State.STATE_LEFT_FIREBALL) {
ball.getBody().setLinearVelocity(-1.0f, 0);
} else if (ball.getBody().getLinearVelocity().x == -0.2f && ball.STATE == State.STATE_LEFT_FIREBALL) {
ball.getBody().setLinearVelocity(-1.0f, 0);
}
//檢查是否Alive
if (!checkAlive(ball)) {
world.destroyBody(ball.getBody());
balls.removeValue(ball, true);
}
}
}
示例2: setStance
import com.badlogic.gdx.physics.box2d.World; //導入方法依賴的package包/類
private void setStance(Entity entity, String stance) {
logger.info("set stance: " + stance);
PhysicsComponent physics = Mappers.physics.get(entity);
PlayerComponent player = Mappers.player.get(entity);
AssetManager assetManager = Env.getGame().getAssetManager();
World world = physicsSystem.getWorld();
if (world.getBodyCount() > 0 &&
physics.body != null) {
world.destroyBody(physics.body);
}
PhysicsData physicsData = assetManager.get(stance, PhysicsData.class);
physics.body = physicsData.createBody(world, entity);
Array<Fixture> fixtures = physics.body.getFixtureList();
player.fixture = fixtures.get(physicsData.getFixtureIdx("main"));
player.feetSensor = fixtures.get(physicsData.getFixtureIdx("feet"));
NodeComponent node = Mappers.node.get(entity);
NodeUtils.computeWorld(entity);
physics.body.setTransform(node.position, node.angle);
}
示例3: checkDestroy
import com.badlogic.gdx.physics.box2d.World; //導入方法依賴的package包/類
public void checkDestroy(float x, float y)
{
if(Utils.pointInRectangle(getBoundingRectangle(),new Vector2(x, y))) {
World world = getBody().getWorld();
world.destroyBody(getBody());
((BaseGameScene)getGameService().getCurrentScene()).remove(this);
}
}
示例4: disposeBox2D
import com.badlogic.gdx.physics.box2d.World; //導入方法依賴的package包/類
public void disposeBox2D(int levelID) {
World world = Game_AI_TestBed.instance().getLevel(levelID).getWorldBox2D();
if (body != null) {
body.setUserData(null);
world.destroyBody(body);
body = null;
} else {
//occurs during double kill calls from sprite sim, need some sort of queue remove system? also one for stopping further code processing
Logger.warn("tried to kill phys body when it was already null'd");
}
}
示例5: process
import com.badlogic.gdx.physics.box2d.World; //導入方法依賴的package包/類
@Override
protected void process(int entityId) {
Bomb bomb = mBomb.get(entityId);
State state = mState.get(entityId);
RigidBody rigidBody = mRigidBody.get(entityId);
Body body = rigidBody.body;
bomb.countDown -= world.getDelta();
if (bomb.countDown <= 0) {
// explode
bomb.state = Bomb.State.EXPLODING;
}
switch (bomb.state) {
case EXPLODING:
state.setCurrentState("exploding");
GameManager.getInstance().playSound("Explosion.ogg", 1.0f, MathUtils.random(0.6f, 0.8f), 0);
// create explosion
ActorBuilder actorBuilder = ActorBuilder.init(body.getWorld(), world);
actorBuilder.createExplosion(body.getPosition().x, body.getPosition().y, bomb.power);
// destroy itself
World b2dWorld = body.getWorld();
b2dWorld.destroyBody(body);
world.delete(entityId);
break;
case MOVING_UP:
if (checkMovable(body, fromV.set(body.getPosition()), toV.set(body.getPosition().x, body.getPosition().y + 0.55f))) {
body.setLinearVelocity(0, bomb.speed);
} else {
body.setLinearVelocity(0, 0);
body.setTransform(MathUtils.floor(body.getPosition().x) + 0.5f, MathUtils.floor(body.getPosition().y) + 0.5f, 0);
bomb.state = Bomb.State.NORMAL;
}
break;
case MOVING_DOWN:
if (checkMovable(body, fromV.set(body.getPosition()), toV.set(body.getPosition().x, body.getPosition().y - 0.55f))) {
body.setLinearVelocity(0, -bomb.speed);
} else {
body.setLinearVelocity(0, 0);
body.setTransform(MathUtils.floor(body.getPosition().x) + 0.5f, MathUtils.floor(body.getPosition().y) + 0.5f, 0);
bomb.state = Bomb.State.NORMAL;
}
break;
case MOVING_LEFT:
if (checkMovable(body, fromV.set(body.getPosition()), toV.set(body.getPosition().x - 0.55f, body.getPosition().y))) {
body.setLinearVelocity(-bomb.speed, 0);
} else {
body.setLinearVelocity(0, 0);
body.setTransform(MathUtils.floor(body.getPosition().x) + 0.5f, MathUtils.floor(body.getPosition().y) + 0.5f, 0);
bomb.state = Bomb.State.NORMAL;
}
break;
case MOVING_RIGHT:
if (checkMovable(body, fromV.set(body.getPosition()), toV.set(body.getPosition().x + 0.55f, body.getPosition().y))) {
body.setLinearVelocity(bomb.speed, 0);
} else {
body.setLinearVelocity(0, 0);
body.setTransform(MathUtils.floor(body.getPosition().x) + 0.5f, MathUtils.floor(body.getPosition().y) + 0.5f, 0);
bomb.state = Bomb.State.NORMAL;
}
break;
case NORMAL:
default:
state.setCurrentState("normal");
break;
}
}