【问题标题】:Java LibGDX: How to get a map based coordinate system?Java LibGDX:如何获得基于地图的坐标系?
【发布时间】:2016-11-12 21:31:20
【问题描述】:

我正在使用 LibGDX 制作 2D 等距平铺游戏。在我的 Player 类中,我创建了一个我命名为 'pos' 的 vector2 来管理玩家的位置,然后我绘制了我的 Player:

batch.begin();
batch.draw(localPlayer.texture,LocalPlayer.pos.x,LocalPlayer.pos.y);
batch.end();

假设 pos = (0,0),那么 Player 将呈现在我屏幕的左下角。

当我平移相机时,(0,0) 仍然对应我屏幕的左下角,所以 pos Vector2 是关于我的屏幕,而不是我的地图...

我应该怎么做才能获得基于地图而不是屏幕上的坐标系?我不喜欢使用 Sprite 类...

谢谢你:)

【问题讨论】:

  • 你试过打电话给batch.setProjectionMatrix(camera.combined)吗?

标签: java libgdx coordinates game-engine isometric


【解决方案1】:

Basim Khajwal 是对的,

调用 batch.setProjectionMatrix(camera.combined) 效果很好:)

但是,如果您正在寻找更深入的理解,您也可以在这里阅读这篇文章:

http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/

其中“视图位置”是您的屏幕位置,“模型位置”是您的地图位置。

【讨论】:

  • 感谢您回答自己的问题并保持这个地方整洁。在这里,再投一个赞成票,并有足够的声誉来制作 cmets。
猜你喜欢
  • 1970-01-01
  • 2013-02-15
  • 1970-01-01
  • 1970-01-01
  • 2015-01-11
  • 2012-07-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多