当前位置: 首页>>代码示例>>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;未经允许,请勿转载。