晚安的朋友。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
謝謝。
丹尼斯再次感謝你。當我回家時,我會嘗試。有什麼地方可以看到你的比賽嗎? – Lovera
它工作得很好。非常感謝你。 – Lovera