问题
i am trying to get to divide and i keep getting this error ?
gradle error; incompatible types; possible lossy conversion from double to 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);
}
回答1:
If you are calling a method that accepts a float
, but you are passing it a double
, the double
must be explicitly converted to a float
. You can do this by putting (float)
in front of each argument. For example:
shape.setAsBox((float) (bounds.getWidth()/2/MyGdxGame.PPM),
(float) (bounds.getHeight()/2/MyGdxGame.PPM));
来源:https://stackoverflow.com/questions/35135442/possible-lossy-conversion-from-double-to-float