2016-08-18 62 views
0

晚安的朋友。libgdx固定点camera.rotateAround

我无法在屏幕旋转时在屏幕上绘制固定点。我从玩家的位置使用了“rotateAround”方法。

在我看来。我必须从玩家的位置旋转这个固定点。我用这个在这里学习的弹力在stackoverflow。

public void rotate(Vector3 position, Vector3 centerPoint){ 
    this.cosTemp = MathUtils.cosDeg(this.anguloAtual); 
    this.senTemp = MathUtils.sinDeg(this.anguloAtual); 

    this.xTemp = centerPoint.x + ((position.x - centerPoint.x) * this.cosTemp) - ((position.y - centerPoint.y) * this.senTemp); 
    this.yTemp = centerPoint.y + ((position.y - centerPoint.y) * this.cosTemp) + ((position.x - centerPoint.x) * this.senTemp); 

    position.set(this.xTemp, this.yTemp, 0); 
} 

在屏幕上显示的玩家。我使用了播放器的位置,然后调用“camera.project”,然后使用“旋转”方法。固定点出现,但它不完全固定。 我使用稍微超前玩家的固定点的例子。

public void meDesenhar(SpriteBatch spriteBatch) { 

    spriteBatch.begin(); 
    this.spritePlayer.setPosition(this.positionPlayer.x - (this.spritePlayer.getWidth()/2), 
            this.positionPlayer.y - this.spritePlayer.getHeight()/2); 

    this.spritePlayer.draw(spriteBatch); 
    spriteBatch.end(); 

    originPosition.set(positionPlayer, 0); 
    fixedPosition.set(positionPlayer.x, positionPlayer.y + 10, 0); 

    cameraTemp.project(fixedPosition); 
    cameraTemp.project(originPosition); 

    cameraManagerTemp.rotate(fixedPosition, originPosition); 
    Debugagem.drawPointInScreen(Color.BLUE, fixedPosition); 
} 

我的问题:

1 - 我做错了什么,或者只是它是四舍五入的结果?我在调试时意识到。在“camera.project”之后,玩家的位置每转一圈都会改变一下。示例位置(540,320)转动(539.99,320.013)

2 - 我尝试使用并享受SpriteBatch绘制方法来执行旋转,但是无法从播放器进行旋转。我会得到同样的结果。

3 - 我可以使用两个摄像头吗?每个相机将是一个图层。在地图上的相机和玩家会。另一个是固定点。它是可行的?我找不到可以同时处理多个相机的任何示例。任何人都请知道任何例子。我不是在谈论悬挂式或摄像机的舞台。

视频如下。

https://www.youtube.com/watch?v=1Vg8haN5ULE

谢谢。

回答

1
  1. 它可能是舍入的结果,因为它移动了一个像素。
  2. 您可以计算玩家的旋转角度,但不需要。
  3. 当然,您可以在游戏中使用多个摄像头,在这种情况下也应该使用多个摄像头。

它从我的旧项目的一些截图,我用多台摄像机 enter image description here enter image description here

正如你可以看到你甚至可以使用不同类型的相机一样的邻位和角度2D和3D。

只要创建新的照相机如第一个和改变投影矩阵

camrotate = new OrthographicCamera(540, 960); 
//... 
camfixed = new OrthographicCamera(540, 960); 
//... 

而在渲染方法

batch.setProjectionMatrix(camrotate.combined); 
batch.begin(); 
//draw in camrotate now 
//... 
//... 
batch.end(); 

batch.setProjectionMatrix(camfixed.combined); 
batch.begin(); 
//draw fixed elements now 
//... 
//... 
batch.end(); 
//add one more camera if you need 

编辑: batch.begin以外 变更投影矩阵()/结束()否则当前批次将被刷新。

+0

丹尼斯再次感谢你。当我回家时,我会尝试。有什么地方可以看到你的比赛吗? – Lovera

+0

它工作得很好。非常感谢你。 – Lovera