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


Java Body.setLinearVelocity方法代码示例

本文整理汇总了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;
    }
 
开发者ID:ZephyrVentum,项目名称:FlappySpinner,代码行数:20,代码来源:WorldUtils.java

示例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;
   }
 
开发者ID:game-libgdx-unity,项目名称:GDX-Engine,代码行数:28,代码来源:Bird.java

示例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;
    }
 
开发者ID:ZephyrVentum,项目名称:FlappySpinner,代码行数:15,代码来源:WorldUtils.java


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