2016-08-18 41 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