當前位置: 首頁>>代碼示例>>Java>>正文


Java Body.setTransform方法代碼示例

本文整理匯總了Java中com.badlogic.gdx.physics.box2d.Body.setTransform方法的典型用法代碼示例。如果您正苦於以下問題:Java Body.setTransform方法的具體用法?Java Body.setTransform怎麽用?Java Body.setTransform使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.badlogic.gdx.physics.box2d.Body的用法示例。


在下文中一共展示了Body.setTransform方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createWall

import com.badlogic.gdx.physics.box2d.Body; //導入方法依賴的package包/類
/**
 * Creates a wall by constructing a rectangle whose corners are (xmin,ymin) and (xmax,ymax),
 * and rotating the box counterclockwise through the given angle, with specified restitution.
 */
public static Body createWall(World world, float xmin, float ymin, float xmax, float ymax,
        float angle, float restitution) {
    float cx = (xmin + xmax) / 2;
    float cy = (ymin + ymax) / 2;
    float hx = Math.abs((xmax - xmin) / 2);
    float hy = Math.abs((ymax - ymin) / 2);
    PolygonShape wallshape = new PolygonShape();
    // Don't set the angle here; instead call setTransform on the body below. This allows future
    // calls to setTransform to adjust the rotation as expected.
    wallshape.setAsBox(hx, hy, new Vector2(0f, 0f), 0f);

    FixtureDef fdef = new FixtureDef();
    fdef.shape = wallshape;
    fdef.density = 1.0f;
    if (restitution>0) fdef.restitution = restitution;

    BodyDef bd = new BodyDef();
    bd.position.set(cx, cy);
    Body wall = world.createBody(bd);
    wall.createFixture(fdef);
    wall.setType(BodyDef.BodyType.StaticBody);
    wall.setTransform(cx, cy, angle);
    return wall;
}
 
開發者ID:StringMon,項目名稱:homescreenarcade,代碼行數:29,代碼來源:Box2DFactory.java

示例2: applyRotation

import com.badlogic.gdx.physics.box2d.Body; //導入方法依賴的package包/類
public void applyRotation(Field field, double dt) {
    currentAngle += dt*rotationSpeed;
    if (currentAngle>TAU) currentAngle -= TAU;
    if (currentAngle<0) currentAngle += TAU;
    for(int i=0; i<elementIDs.length; i++) {
        double angle = currentAngle + angleIncrement*i;

        FieldElement element = field.getFieldElementById(elementIDs[i]);
        Body body = element.getBodies().get(0);
        double x = centerX + radius*Math.cos(angle);
        double y = centerY + radius*Math.sin(angle);
        body.setTransform((float)x, (float)y, body.getAngle());
    }
}
 
開發者ID:StringMon,項目名稱:homescreenarcade,代碼行數:15,代碼來源:Field2Delegate.java


注:本文中的com.badlogic.gdx.physics.box2d.Body.setTransform方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。