相机阻止玩家正确旋转面对鼠标

时间:2018-05-16 21:36:51

标签: java graphics rotation translate drawing2d

我目前正在进行2D游戏,我希望玩家能够自由地在世界各地移动并始终“面对/看”鼠标。为了实现这一点,我制作了一个Camera,它可以翻译与玩家相关的所有内容:

x = (player.getX()+(player.getWidth()/2)) - game.getWidth()/2;
y = (player.getY()+(player.getHeight()/2)) - game.getHeight()/2;

g2d.translate(-camX, -camY);
//render everything(including player)
g2d.translate(camX, camY);

然后在渲染玩家时我计算旋转:

g2d.rotate(Math.atan2(playerCenterY - mouseY, playerCenterX - mouseX) - Math.PI / 2 , playerCenterX , playerCenterY );
//draw player
g2d.rotate(-Math.atan2(playerCenterY - mouseY, playerCenterX - mouseX) - Math.PI / 2 , playerCenterX , playerCenterY );

这很有效但是一旦玩家移动(导致相机移动)它就不再有效了,我不知道为什么。任何想法都将不胜感激。

0 个答案:

没有答案