本文整理汇总了Java中com.badlogic.gdx.physics.box2d.Body.setLinearVelocity方法的典型用法代码示例。如果您正苦于以下问题:Java Body.setLinearVelocity方法的具体用法?Java Body.setLinearVelocity怎么用?Java Body.setLinearVelocity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.physics.box2d.Body
的用法示例。
在下文中一共展示了Body.setLinearVelocity方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTopTube
import com.badlogic.gdx.physics.box2d.Body; //导入方法依赖的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;
}
示例2: onTouchUp
import com.badlogic.gdx.physics.box2d.Body; //导入方法依赖的package包/类
@Override
public boolean onTouchUp(TouchEvent e) {
if (status != Status.touched) {
return true;
}
// If mouse is up when dragging the bird
// fire the bird
float distanceX = getCenterX() - sling.getCenterX();
float distanceY = getCenterY() - sling.getCenterY();
// Here we have velocityX and velocityY of bird
float velocityX = distanceX * -1 / 5;
float velocityY = distanceY * -1 / 5;
Vector2 birdVelocity = new Vector2(velocityX, velocityY);
// get PhysicManager from gameService
PhysicsManager physicsManager = getGameService().getService(
PhysicsManager.class);
// create new physicObject in physicsManager
Body birdBody = physicsManager.addDynamicCircleObject(this,
getRegionWidth() / 2, 4f, 0.8f, 0.5f);
// Set above velocity for the bird body
birdBody.setLinearVelocity(birdVelocity);
// set bullet, it will make game run preciously
birdBody.setBullet(true);
// update the bird's status
status = Status.released;
return false;
}
示例3: createBottomTube
import com.badlogic.gdx.physics.box2d.Body; //导入方法依赖的package包/类
public static Body createBottomTube(World world, float posX, float posY) {
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyDef.BodyType.KinematicBody;
bodyDef.position.set(posX, posY - Constants.TUBE_SPACING - 30);
PolygonShape shape = new PolygonShape();
shape.setAsBox(Constants.TUBE_WIDTH / 2, Constants.TUBE_HEIGHT / 2);
Body body = world.createBody(bodyDef);
body.createFixture(shape, 0f);
body.resetMassData();
shape.dispose();
body.setLinearVelocity(Constants.TUBE_SPEED, 0.0f);
return body;
}