我想出了我的光标的x和y转换为角度然而问题是我的精灵正面向相反的方向。
这是代码
@Override
public void create() {
bida = new Texture(Gdx.files.internal("data/alienblaster.png"));
tR = new TextureRegion(bida);
bucket = new Rectangle();
bucket.x = 800 / 2 - bida.getWidth() / 2; // center the bucket horizontally
bucket.y = 400/2;
/*bucket.x = Gdx.graphics.getWidth() - bida.getWidth();
bucket.y = Gdx.graphics.getHeight() - bida.getHeight();*/
bucket.width = bida.getWidth();
bucket.height = bida.getHeight();
bullets = new Array<Rectangle>();
spawnRaindrop();
camera = new OrthographicCamera();
camera.setToOrtho(true, 800, 480);
front = 270;
batch = new SpriteBatch();
Gdx.input.setInputProcessor(this);
}
@Override
public void render() {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
camera.update();
batch.setProjectionMatrix(camera.combined);
batch.begin();
{
//batch.draw(bida,bucket.x,bucket.y, 50,50);
batch.draw(tR, bucket.x, bucket.y, bucket.getWidth()/2 /*center x of image where it will rotate*/, bucket.getHeight()/2 /*center y of image where it will rotate*/, bucket.getWidth() , bida.getHeight(), 1, 1, front);
}
batch.end();
}
@Override
public boolean mouseMoved(int screenX, int screenY) {
float dx = screenX - bucket.x; // cursor x and sprite x coordinates
float dy = screenY - bucket.y; // cursor y and sprite y coordinates
float secondSolution =MathUtils.radiansToDegrees*MathUtils.atan2(dx, dy);
double firstSolution = Math.toDegrees(Math.atan2(dx,dy));
front = secondSolution;
Gdx.app.log("","" + firstSolution+ " " + secondSolution);
return true;
}
,jar文件为here
这里有什么问题?
答案 0 :(得分:0)
代替camera.setToOrtho(true,800,480);使用 camera.setToOrtho(false,800,480);