我正在制作一个2D sidescroller,我想把我的精灵画到世界空间而不是客户空间,所以我不必将它锁定到屏幕的中心,当相机停止时,精灵将走出屏幕而不是被卡住在中心。 为了做到这一点,我想制作一个转换矩阵,在我的绘制调用中。 我见过这样的东西: XNA ViewPort投影和Sprit ...
提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文繁体 英文版本 中英对照 版本,有任何建议请联系yoyou2525@163.com。
我正在尝试以世界单位获取触摸坐标,以便我可以使用 viewport.unproject(Vector3) 在屏幕上绘制纹理,但它返回的是 NaN。
我的视口和相机如下所示:
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();
}
. . .
我有一个 GameScreen class 实现屏幕并具有 GameRenderer 的实例,因此调用 init() 方法。
这是我尝试过的:
Public class GameController
. . .
private void updateShip() {
ship.setPositions(renderer.getViewport().unproject(ship.getTouchPos()));
log.debug(Float.toString(renderer.getViewport().unproject(ship.getTouchPos()).x));
}
. . .
其中 ship.getTouchPos 返回 Gdx.input.getX() 和 y 的 Vector3。
显然,我在 GameController 中有一个 GameRenderer 实例来获取视口并使用它将触摸坐标转换为世界坐标。
log.debug output:
I/chatty: uid=10133(com.mygdx.game) GLThread 342 identical 2 lines
D/GameController: NaN
D/GameController: NaN
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.