【发布时间】:2016-02-01 16:28:28
【问题描述】:
我正在尝试分裂,但我不断收到此错误?
分级错误;不兼容的类型;从 double 到 float 的可能有损转换?
protected World world;
protected TiledMap map;
protected TiledMapTile tile;
protected Rectangle bounds;
protected Body body;
public InteractiveTileObject(World world, TiledMap map, Rectangle bounds ){
this.world = world;
this.map = map;
this.bounds = bounds;
BodyDef bdef = new BodyDef();
FixtureDef fdef = new FixtureDef();
PolygonShape shape = new PolygonShape();
bdef.type = BodyDef.BodyType.StaticBody;
bdef.position.set((bounds.getX() + bounds.getWidth()/2)/MyGdxGame.PPM, (bounds.getY() + (bounds.getHeight() / 2)) / MyGdxGame.PPM);
body = world.createBody(bdef);
shape.setAsBox(bounds.getWidth()/2 /MyGdxGame.PPM, bounds.getHeight()/2 /MyGdxGame.PPM);
fdef.shape = shape;
body.createFixture(fdef);
}
【问题讨论】:
-
如果您调用的方法接受
float但传递给它double,则double必须转换为float。例如,将(float)放在参数前面。 -
我调用的唯一两个方法是 set 和 setAsBox 吗?我如何转换这些?
-
把
(float)放在每个参数的前面。例如。setAsBox((float) (bounds.getWidth()/2 /MyGdxGame.PPM), (float) (bounds.getHeight()/2 /MyGdxGame.PPM));