當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。