问题描述
晚安朋友.
旋转屏幕时,我无法在屏幕上绘制固定点.我从播放器的位置使用了"rotateAround"方法.
I'm having trouble drawing a fixed point on the screen when the screen is rotated. I used the method "rotateAround" from the position of the player.
在我看来.我还必须从播放器的位置旋转此固定点.我使用这里在stackoverflow中学习到的这种拉伸方式.
It seems to me. I have to rotate this fixed point also from the position of the player. I use this stretch learned here in 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",然后使用了旋转"方法.出现固定点,但是并没有完全固定.我以固定点为例,稍稍领先于播放器.
In the drawing that the player on the screen. I used the position of the player, then called "camera.project" then the method "rotate". The fixed point appears, however it is not exactly fixed.I used the example of a fixed point slightly ahead of the player.
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)
1 - I am doing something wrong, or just it is a result of rounding? I realized when debugging. The position of the player changed a little every rotation after the "camera.project". Example position (540, 320) turned (539.99, 320.013)
2-我尝试使用SpriteBatch的draw方法来享受旋转效果,但是无法从播放器进行旋转.我会得到相同的结果.
2 - I tried using and enjoying the SpriteBatch the draw method to perform the rotation however, could not make the rotation from the player. I would arrive at the same result.
3-我可以使用两台相机吗?每个摄像机将是一个图层.地图上的相机和播放器都可以.另一个为定点.可行吗?我找不到同时使用多个摄像头的任何示例.任何人都知道任何例子.我不是在谈论要上演的Hud或摄影机.
3 - Can I use two cameras? Each camera would be a layer. A camera at the map and the player would be. The other for fixed point. It's viable? I could not find any example that works with more than one camera at the same time. Anyone know any examples please. I'm not talking about huds or cameras to stage.
跟随视频.
https://www.youtube.com/watch?v=1Vg8haN5ULE
谢谢.
推荐答案
- 可能是舍入的结果,因为它移动了一个像素.
- 您可以从播放器计算旋转角度,但这不是必需的.
- 当然,您可以在游戏中使用多个摄像机,在这种情况下也应该使用.
我使用多个摄像头的旧项目中的一些屏幕截图
Its few screenshot from my old projects that i used multiple cameras
如您所见,您甚至可以同时使用2D和3D等不同类型的摄像机,例如正交摄像机和透视摄像机.
As you can see you can even use different type of cameras like ortho and perspective both 2D and 3D.
只需像第一个那样创建新相机并更改投影矩阵
Just create new camera like first one and change projection matrix
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()/end()外部更改投影矩阵,否则将刷新当前批次.
Change projection matrix outside of batch.begin()/end() otherwise the current batch will flushed.
这篇关于libgdx camera.rotateAround之后的固定点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!