本文整理汇总了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;
}
}