我想分裂,我一直收到这个错误?
gradle错误;不相容的类型;可能有损转换从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);
}
答案 0 :(得分:1)
如果您正在调用接受float
的方法,但是传递的是double
,则必须将double
显式转换为float
。您可以通过将(float)
放在每个参数前面来完成此操作。例如:
shape.setAsBox((float) (bounds.getWidth()/2/MyGdxGame.PPM),
(float) (bounds.getHeight()/2/MyGdxGame.PPM));