2013-05-06 69 views
-1

我想出了將光標的x和y轉換爲角度的轉換,然而問題是我的精靈正面臨反方向。面向其他方式的角度libgdx

這裏是代碼

@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

代替camera.setToOrtho(true,800,480);使用 camera.setToOrtho(false,800,480);