2016-11-17 9 views
0

のサイズを変更私は(私のボディラッパーの内部で)この方法では、遺体upponスプライトを描画しています:私は窓のサイズを変更しようとするまでボディにスプライトを描画 - カメラビューポートと

private void drawBaseSprite(Batch batch){ 
     Sprite baseSprite = this.getBaseSprite(); 

     Vector3 bodyPixelPos = camera.project(new Vector3(body.getPosition().x, body.getPosition().y, 0)); 

     // TODO: 17/11/16 Review this 
     float w = scale * (baseSprite.getTexture().getWidth())/camera.zoom; 
     float h = scale * (baseSprite.getTexture().getHeight())/camera.zoom ; 

     baseSprite.setSize(w,h); 
     baseSprite.setOrigin(w/2, h/2); 
     baseSprite.setPosition(bodyPixelPos.x -w/2, bodyPixelPos.y - h/2); 
     baseSprite.setRotation(body.getAngle() * MathUtils.radiansToDegrees); 


     baseSprite.draw(batch); 
    } 

すべてが、良いです。リサイズ前

@Override 
public void resize(int width, int height) { 
    stage.getViewport().update(width, height, true); 
    stage.camera.setToOrtho(false, Constants.VIEWPORT_HEIGHT *width/(float)height, Constants.VIEWPORT_HEIGHT); 
} 

:まあ、私はこのサイズ変更ロジックを(画面を実装)は、次のよ before resize リサイズ(広い幅)後: after resize (larger width)

私はこれが不条理見つけるこのため:

 float w = scale * (baseSprite.getTexture().getWidth())/camera.zoom; 
     float h = scale * (baseSprite.getTexture().getHeight())/camera.zoom ; 

は変更されませんが、画像はx軸で表示されます。

答えて

0

体の上に画像が残っていないことがわかりましたか?

もしそうなら、それはあなたがカバーしなければならないボディにではなく、カメラに対してイメージのサイズを設定していることです。カメラのズームが変更されると、画像のサイズは調整されますが、ボディは調整されず、同期が外れます。

イメージの高さ/幅が純粋にボディによって決定され、ボディがカメラのズームに基づいてスケーリングされるようにロジックを変更することをお勧めします。

+0

答えるためのおかげで、私はスプライトのサイズを追跡: Gdx.app.log(this.getClass()getSimpleName()、 "W: "+ W +" H:" + H)。 カメラのズームが変更されず(ビューポートのみが変更されるため)、サイズ変更後も変更されません。 – neogineer

0

これは私の問題を解決しましたが、私はまだそれほど深くは分かりません。

private void drawBaseSprite(Batch batch){ 
     Sprite baseSprite = this.getBaseSprite(); 
     batch.setProjectionMatrix(camera.combined); 
     float someScale = 0.1f; 

     float w = scale * (baseSprite.getTexture().getWidth())/camera.zoom *someScale; 
     float h = scale * (baseSprite.getTexture().getHeight())/camera.zoom *someScale; 


     Vector3 bodyPixelPos = camera.project(new Vector3(body.getPosition().x, body.getPosition().y, 0)) 
       .scl(someScale*camera.viewportHeight/(Gdx.graphics.getHeight()/20f)).sub(w/2, h/2, 0); 

     baseSprite.setSize(w,h); 
     baseSprite.setOrigin(w/2, h/2); 
     baseSprite.setPosition(bodyPixelPos.x, bodyPixelPos.y); 
     baseSprite.setRotation(body.getAngle() * MathUtils.radiansToDegrees); 

     baseSprite.draw(batch); 
    } 
関連する問題