我正在尝试制作像小行星一样的游戏,我希望玩家面对并向上移动(向北),但是当游戏开始时,玩家面对的是右侧(向东)。这是我的代码:
public Player(float x, float y,int width,int height) {
this.width = width;
this.height = height;
this.x = x;
this.y = y;
}
public void update(float delta) {
if(up) {
x += Math.cos(Math.toRadians(rotation)) * Constants.PLAYER_SPEED * delta;
y += Math.sin(Math.toRadians(rotation)) * Constants.PLAYER_SPEED * delta;
}else if(right){
rotation -= Constants.PLAYER_ROTATION * delta;
}else if(left){
rotation += Constants.PLAYER_ROTATION * delta;
}
wraparound();
}
然后我从纹理区域中绘制我的播放器,如下所示:
batch.draw(playerTR, player.getX(),player.getY(),
player.getWidth()/2.0f,player.getHeight()/2.0f,
player.getWidth(),player.getHeight(),1,1,player.getRotation());
请一些帮助我。
rotation
默认情况下,您的变量被初始化为0。尝试将其初始化为90,您的播放器应开始朝北:
public Player(float x, float y,int width,int height) {
...
rotation = 90.0f;
}
您的其余代码似乎可以处理它。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句