简体   繁体   中英

Angle facing other way libgdx

I figured out the convertion of x and y of my cursor to angle however the problem is my sprite is facing the oposite direction.

here is the code

@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;
    }

and the jar file is here

what is the problem here?

In place of camera.setToOrtho(true, 800, 480); use camera.setToOrtho(false, 800, 480);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM