Java Viewport.unject()返回NaN(不是数字)
我正在尝试以世界单位获取触摸坐标,这样我就可以使用viewport.unproject(Vector3)在屏幕上绘制纹理,但它正在返回NaN 我的视口和相机的显示如下:Java Viewport.unject()返回NaN(不是数字),java,android,libgdx,Java,Android,Libgdx,我正在尝试以世界单位获取触摸坐标,这样我就可以使用viewport.unproject(Vector3)在屏幕上绘制纹理,但它正在返回NaN 我的视口和相机的显示如下: public class GameRenderer { private InvadersGame game; private Viewport viewport; private OrthographicCamera camera; private SpriteBatch batch;
public class GameRenderer {
private InvadersGame game;
private Viewport viewport;
private OrthographicCamera camera;
private SpriteBatch batch;
private Animation<TextureRegion> shipAnimation;
private TextureRegion currentShipFrame;
private Ship ship;
private CameraDebug cameraDebug;
private DebugCameraConfig debugCameraConfig;
private TextureAtlas shipAtlas;
private float timeElapsed;
public GameRenderer(InvadersGame game) {
this.game = game;
init();
}
private void init() {
camera = new OrthographicCamera();
viewport = new FitViewport(GameConfig.WORLD_WIDTH, GameConfig.WORLD_HEIGHT, camera);
batch = new SpriteBatch();
shipAtlas = new TextureAtlas(Gdx.files.internal(AssetPaths.shipAnimation));
shipAnimation = new Animation<TextureRegion>(1/10f, shipAtlas.findRegions("ship"), Animation.PlayMode.LOOP);
ship = new Ship();
cameraDebug = new CameraDebug();
debugCameraConfig = new DebugCameraConfig();
}
. . .
其中ship.getTouchPos返回Gdx.input.getX()和y的向量3
显然,我在GameController中有一个GameRenderer实例来获取视口,并使用它将触摸坐标转换为世界坐标
log.debug输出:
I/chatty: uid=10133(com.mygdx.game) GLThread 342 identical 2 lines
D/GameController: NaN
D/GameController: NaN
如何设置视口?LibGDX的摄像头中似乎存在一个bug,如果您的摄像头的宽度或高度为1,它将返回NaN。我认为unproject使用矢量3,getTouchPos()返回矢量2,因此您可能必须转换为矢量3否,有一个重载的Vector2版本。@Tenfour04我已经相应地编辑了我的问题,您的
WORLD\u WIDTH
或WORLD\u HEIGHT
是否等于一?您的视口是如何设置的?LibGDX的摄像头中似乎存在一个bug,如果您的摄像头的宽度或高度为1,它将返回NaN。我认为unproject使用矢量3,getTouchPos()返回矢量2,因此您可能必须转换为矢量3否,有一个重载的Vector2版本。@Tenfour04我已经相应地编辑了我的问题,您的世界宽度
还是世界高度
等于一?
I/chatty: uid=10133(com.mygdx.game) GLThread 342 identical 2 lines
D/GameController: NaN
D/GameController: NaN